是否有可能缩小y轴?我的意思是代替图是方形的,我希望它是矩形的,y轴收缩.
library(ggplot2)
data = data.frame(rnorm(10000))
colnames(data) = "numOfX"
m <- ggplot(data, aes(x=numOfX))
m + geom_histogram(colour = "blue", fill = "white", binwidth = 0.5)
Run Code Online (Sandbox Code Playgroud) 我试图将rowname与所需列中的数据粘贴在一起.我写了下面的代码,但不知何故找不到正确的方法.
所需的输出将是: "a,1,11" "b,2,22" "c,3,33"
x = data.frame(cbind(f1 = c(1,2,3), f2 = c(5,6,7), f3=c(11,22,33)), row.names= c('a','b','c'))
x
# f1 f2 f3
# a 1 5 11
# b 2 6 22
# c 3 7 33
do.call("paste", c(rownames(x), x[c('f1','f3')], sep=","))
# [1] "a,b,c,1,11" "a,b,c,2,22" "a,b,c,3,33"
Run Code Online (Sandbox Code Playgroud) 我有一个2-d字典,格式如下:
myDict = {('a','b'):10, ('a','c'):20, ('a','d'):30, ('b','c'):40, ('b','d'):50,('c','d'):60}
Run Code Online (Sandbox Code Playgroud)
如何将其写入制表符分隔文件,以便该文件包含以下内容.填充元组(x,y)将填充两个位置:(x,y)和(y,x).(x,x)始终为0.
输出将是:
a b c d
a 0 10 20 30
b 10 0 40 50
c 20 40 0 60
d 30 50 60 0
Run Code Online (Sandbox Code Playgroud)
PS:如果以某种方式将字典转换为数据帧(使用pandas),那么可以使用pandas函数将其轻松写入文件
我有一个包含以下内容的大文件:
filename:input.txt
>chr1
jdlfnhl
dh,ndh
dnh.
dhjl
>chr2
dhfl
dhl
dh;l
>chr3
shgl
sgl
>chr2_random
dgld
Run Code Online (Sandbox Code Playgroud)
我需要拆分这个文件,以便我得到四个单独的文件,如下所示:
文件1:chr1.fa
>chr1
jdlfnhl
dh,ndh
dnh.
dhjl
Run Code Online (Sandbox Code Playgroud)
文件2:chr2.fa
>chr2
dhfl
dhl
dh;l
Run Code Online (Sandbox Code Playgroud)
文件3:chr3.fa
>chr3
shgl
sgl
Run Code Online (Sandbox Code Playgroud)
文件4:chr2_random.fa
>chr2_random
dgld
Run Code Online (Sandbox Code Playgroud)
我在linux中尝试了csplit,但是在">"之后不能立即通过文本重命名它们.
csplit -z input.txt '/>/' '{*}'
Run Code Online (Sandbox Code Playgroud) 如何避免出现以下错误.as.formula()似乎不接受以数字开头并后跟_(下划线)的变量.我正在动态生成这些变量,我处于一个我不想返回并更改变量名称的阶段.谢谢
lhsOfFormula = "25_dep"
rhsOfFormula = "predVar1+predVar2+10_predVar3"
as.formula(paste(lhsOfFormula , " ~ ", rhsOfFormula ))
Run Code Online (Sandbox Code Playgroud)
错误:
> as.formula(paste(lhsOfFormula , " ~ ", rhsOfFormula ))
Error in parse(text = x) : <text>:1:3: unexpected input
1: 25_
^
Run Code Online (Sandbox Code Playgroud) 如何将固定长度的多个列表合并在一起,以获得在特定位置具有最新值的单个列表.在下面的示例中,结果将是[1,33,222,3333,11111].
l1 = [1, "", 111, "", 11111]
l2 = ["", 22, 222, 2222, ""]
l3 = ["", 33, "", 3333, ""]
l4 = ....
l5 = ...
....
Run Code Online (Sandbox Code Playgroud)
有没有内置功能来做到这一点.我可以使用两个循环来完成它,但必须有一些其他聪明的方法来做同样的事情
以下列形式将元组列表转换为表的优雅方法是什么?
输入:
from pandas import DataFrame
mytup = [('a','b',1), ('a','c',2), ('b','a',2), ('c','a',3), ('c','c',1)]
a b 1
a c 2
b a 2
c a 3
c c 1
mydf = DataFrame(mytup, columns = ['from', 'to', 'val'])
Run Code Online (Sandbox Code Playgroud)
输出:-可以替换为空白或nan
a b c
a - 1 2
b 2 - -
c 3 - 1
Run Code Online (Sandbox Code Playgroud) 我有一个数据框,我需要首先应用该数据框,然后获得加权平均值,如下面的输出计算所示。pyspark中执行此操作的有效方法是什么?
data = sc.parallelize([
[111,3,0.4],
[111,4,0.3],
[222,2,0.2],
[222,3,0.2],
[222,4,0.5]]
).toDF(['id', 'val','weight'])
data.show()
+---+---+------+
| id|val|weight|
+---+---+------+
|111| 3| 0.4|
|111| 4| 0.3|
|222| 2| 0.2|
|222| 3| 0.2|
|222| 4| 0.5|
+---+---+------+
Run Code Online (Sandbox Code Playgroud)
输出:
id weigthed_val
111 (3*0.4 + 4*0.3)/(0.4 + 0.3)
222 (2*0.2 + 3*0.2+4*0.5)/(0.2+0.2+0.5)
Run Code Online (Sandbox Code Playgroud) 在下面给出的代码中,我需要将用户ID框放在中心.经过多次尝试,我无法做到这一点.抱歉这么天真.
我的HTML和css文件如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<link rel="stylesheet" type="text/css" href="styledel.css" />
</head>
<body>
<input type="text" name="userid" id="userid"> <!-- this need to go in the center -->
<br/><br/><br/>
<form action="http://localhost" method="post" name="form"">
<label for="name">Name</label>
<input type="text" id="name" name="name" disabled="disabled" />
<br></br>
<label for="email">E - mail</label>
<input type="text" name="email">
<br></br>
<label for="password">Select Password</label>
<input type="password" name="password" >
<br></br>
<label for="password2">Retype Password</label>
<input type="password" name="password2" >
<br></br>
<input type="submit" value="Submit" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的css文件如下:
styledel.css
* { …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个可以匹配以下或类似单词中的任何单词的正则表达式.*在这些字符串中是精确的,*而不是任何字符.
Jump
J**p
J*m*
J***
***p
J***ing
J***ed
****ed
Run Code Online (Sandbox Code Playgroud)
我想保持固定的长度.
1. Any string of lenght 4 that matches the string 'jump'
2. Any string of length 6 that matches 'jumped'
3. Any string of length 7 that matches 'jumping'
Run Code Online (Sandbox Code Playgroud)
我使用以下语句但由于某种原因,我无法正确翻译.它也接受其他字符串.
p = re.compile('j|\*)(u|\*)(m|\*)...)
bool(p.match('******g'))
Run Code Online (Sandbox Code Playgroud) 给定一个字符串text和一个适当的子字符串query.如何删除除第一个以外的查询的所有出现?
例:
text = 'cccsumoxxxsumoppqqsumovvvvsumo'
query = 'sumo'
result: 'cccsumoxxxppqqvvvv'
Run Code Online (Sandbox Code Playgroud)