我有以下数据框:
A B C D Xax
0.451 0.333 0.034 0.173 0.22
0.491 0.270 0.033 0.207 0.34
0.389 0.249 0.084 0.271 0.54
0.425 0.819 0.077 0.281 0.34
0.457 0.429 0.053 0.386 0.53
0.436 0.524 0.049 0.249 0.12
0.423 0.270 0.093 0.279 0.61
0.463 0.315 0.019 0.204 0.23
Run Code Online (Sandbox Code Playgroud)
我需要在同一个图中绘制所有这些列(在x轴上我想要变量Xax,y轴是变量A,B,C和D),并且还要单独绘制每个变量的回归线.
我试过这个:
pl<-ggplot(data=df) + geom_point(aes(x=Xax,y=A,size=10)) +
geom_point(aes(x=Xax,y=B,size=10)) +
geom_point(aes(x=Xax,y=C,size=10)) +
geom_point(aes(x=Xax,y=D,size=10)) +
geom_smooth(method = "lm", se=FALSE, color="black")
Run Code Online (Sandbox Code Playgroud)
但它只绘制了第一个(Xax和A)
我有一个R脚本,可以geom_tile完全按照我的要求生成一个图.
但问题是轴的步长是如此之大 e.g(4000 - 8000 - 12000 - ...)
我想scale_x_continuous('Xaxis',limits = c(...))和scale_x_continuous(breaks=1:10)
但它只限制数据.
我该怎么做才能最小化轴上的步长?
e.g (500 - 1000 - 1500 - 2000 - 2500 ....etc)
Run Code Online (Sandbox Code Playgroud)
谢谢你
我在使用并行处理将值附加到数据框时遇到问题.
我有一个函数会做一些计算并返回一个数据帧,包括这些计算是一个随机抽样.
所以我做的是:
randomizex <- function(testdf)
{
foreach(ind=1:1000)%dopar%
{
testdf$X = sample(testdf$X,nrow(testdf), replace=FALSE)
fit = lm(X ~ Y, testdf)
newdf <- rbind(newdf, data.frame(pc=ind, err=sum(residuals(fit)^2) ))
}
return(newdf)
}
resdf = randomizex(mydf)
Run Code Online (Sandbox Code Playgroud)
当我查看结果时resdf,它是空的
如果我更换%dopar%与%do%结果被正确地计算,但它太慢了..
反正有没有提高这一点?
我有以下数据框架
dd <- data.frame(b = c("High", "Medium", "Highest", "Low", "Not bad","Good", "V. Good"),
x = c("C3", "C1", "C4", "N2", "C2", "N1","N4"), x = c("5", "2", "3", "6", "7", "5","7") )
Run Code Online (Sandbox Code Playgroud)
所以我希望使用变量X的手动顺序转换数据框.
例如:那是原始的
1 High C3 5
2 Medium C1 2
3 Highest C4 3
4 Low N2 6
5 Not bad C2 7
6 Good N1 5
7 V. Good N4 7
Run Code Online (Sandbox Code Playgroud)
但我想要的是一个新的数据框,基于X的值而不是按字母顺序开始,而是按照我选择的顺序随机开始,例如:
the first row has x=C1, the second have x=C2, the third have x=N4, ...etc
Run Code Online (Sandbox Code Playgroud)
怎么做到这一点?
谢谢
我有一个非常大的数据框((35000行),但我希望通过跳过例如100行获得特定的行.
所以在这种情况下每100行我只会得到一行.
我知道可以使用以下方法完成:
N = nrow(dataframe)
for( i in seq(1:N,by=100))
{
out <- rbind(out, data.frame(...)
}
Run Code Online (Sandbox Code Playgroud)
这是否比for循环更容易完成?使用subset或类似的东西
问候
我有一个线性回归问题,我解决了使用:
m=lm(value ~ mean, data=d)
Run Code Online (Sandbox Code Playgroud)
从这个值我可以得到R2和回归方程.
但我想得到标准误差(拟合误差).我能够看到价值,但我不知道如何得到它,以便将其存储在数据框内.
我得到值使用summary(m),结果是这样的:
Call:
lm(formula = value ~ mean, data = d)
Residuals:
Min 1Q Median 3Q Max
-25.000 -15.909 -2.124 14.596 44.697
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.500e+01 1.064e+00 23.49 <2e-16 ***
mean -1.759e-06 1.536e+00 0.00 1
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 16.85 on 1298 degrees of freedom
Multiple R-squared: 1.01e-15, Adjusted R-squared: -0.0007704
F-statistic: 1.311e-12 …Run Code Online (Sandbox Code Playgroud) 这是我第一次在biopython中使用blast,我遇到了问题.
我从fasta文件创建了一个自定义blast数据库,其中包含20个序列,使用:
os.system('makeblastdb -in newtest.fasta -dbtype nucl -out newtest.db')
这确实在我当前工作的当前目录中生成了一些文件(newtest.db.nhr,newtest.db.nin,newtest.db.nsq):( /home/User/Documents/python/fasta-files)
现在我正在尝试使用以下方法在biopython中查询此数据库:
blastx_cline = NcbiblastxCommandline(query="queryfile.fas", db="newtest.db", evalue=0.00000001, outfmt=5, out="opuntia.xml")
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
> Bio.Application.ApplicationError: Command 'blastx -out opuntia.xml
> -outfmt 5 -query queryfile.fas -db newtest.db -evalue 1e-08' returned non-zero exit status 2, 'BLAST Database error: No alias or
> index file found for protein database [newtest.db] in search path
> [/home/User/Documents/python/fasta-files:/usr/share/ncbi/blastdb:]'
Run Code Online (Sandbox Code Playgroud)
所以我尝试复制从生成的文件/home/User/Documents/python/fasta-files,/usr/share/ncbi/blastdb但它说我没有权限.
*编辑*
当我使用:os.system("blastn -db newtest.db -query "fastafile.fas" + " -out test.txt")
它正常生成一个输出文件.但不是相反**
所以我被困在这里,我不知道如何解决这个问题.
任何帮助,将不胜感激
我正在绘制一个geom_tile情节,其中我有一个特定的每个点p-value.
该图以一种很好的方式绘制,并附p-value有图例的限制.
我要添加到此图例的是具有此数据的数据点的数量p-value.
例:
传说是这样的(每个值都有一个颜色):
0.05
0.04
0.03
0.02
0.01
Run Code Online (Sandbox Code Playgroud)
我想拥有的是这样的:
0.05 58
0.04 34
0.03 85
0.02 54
0.01 10
Run Code Online (Sandbox Code Playgroud)
我怎样才能将这个添加到ggplot2情节的传说中?
我尝试使用geom_text并将文本位置更改为图例,但它没有用.
UPDATE
pl <- ggplot(df.new) + geom_tile(aes(fill=z, x, y)) +
scale_fill_gradient(low="yellow", high="red", name="Legend1") +
stat_contour(breaks=c(0.001, 0.01, 0.05), aes(x=x, y=y, z=npvalue, colour=..level..)) +
scale_colour_gradient2(low="black", mid="black", high="green", labels=paste(levels(c(0.001, 0.01, 0.05))))
Run Code Online (Sandbox Code Playgroud)
我有这个情节,我正在geom_tile从z变量中正确绘制然后stat_contour根据p值绘制一个.我想编辑stat_contour基于p-value我的初始问题中的as 的颜色标签,但我有这个错误:
Error in scale_labels.continuous(scale, breaks) :
Breaks and labels …Run Code Online (Sandbox Code Playgroud) 我正在尝试wilcox.test在R中使用显着性测试.我想基本上测试一个值x是否明显在分布内/外d.
我正在做以下事情:
d = c(90,99,60,80,80,90,90,54,65,100,90,90,90,90,90)
wilcox.test(60,d)
Wilcoxon rank sum test with continuity correction
data: 60 and d
W = 4.5, p-value = 0.5347
alternative hypothesis: true location shift is not equal to 0
Warning message:
In wilcox.test.default(60, d) : cannot compute exact p-value with ties
Run Code Online (Sandbox Code Playgroud)
基本上p值对于我测试的大范围数字是相同的.
我已尝试wilcox_test()从coin包中,但我不能让它工作测试分配的价值.
有没有替代这个测试做同样的事情并且知道如何处理关系?
我有一个巨大的文件夹结构,其中有很深的子文件夹,并且这些文件夹内有具有不同扩展名的文件(.txt, .pdf, ...)。
我想要做的是复制整个文件夹结构以及仅具有.pdf扩展名的文件。
我正在使用scp,但没有选项来指定要复制的扩展名。
我尝试rsync使用排除和包含选项,但它也不起作用并且 shell 窗口 forze
PS:我在Mountain Lion,我正在尝试从16MacOSX复制Fedora
做这个的最好方式是什么 ?
我创建了一个将填充数据框的函数,但我忘return df1了在函数结束时写.并且脚本需要很长时间才能完成.所以重新运行它是不可行的.
该函数做了类似的事情:
df < - function(df1){
....对df1的一些操作
返回df1
}
有什么办法可以从函数内部访问这个数据框,然后通常作为全局函数对它应用更多的测试?
也许是这样的: myfunc.df1
我有一个类似的python脚本:
def test_run():
global files_dir
for f1 in os.listdir(files_dir):
for f2 os.listdir(files_dir):
os.system("run program x on f1 and f2")
Run Code Online (Sandbox Code Playgroud)
os.system在不同处理器上调用每个呼叫的最佳方法是什么?使用子进程或多处理池?
注意:程序的每次运行都将生成一个输出文件.