我有一个哈希由两个因素决定(我不知道这是什么正确的术语),我生成如下:
if (exists $cuthash{$chr}{$bin}){
$cuthash{$chr}{$bin} += 1;
}else{
$cuthash{$chr}{$bin} = 1;
}
Run Code Online (Sandbox Code Playgroud)
我后来想要获取哈希的每个$ chr部分的大小,这在我做的时候有效:
for my $chr (sort keys %cuthash){
my $hashsize = keys $cuthash{$chr};
...
}
Run Code Online (Sandbox Code Playgroud)
但我得到警告:
keys on reference is experimental at ../test.pl line 115.
Run Code Online (Sandbox Code Playgroud)
它有效,但显然它并不完美.什么是更好的方法?
谢谢
我试图将一些NMDS坐标绘制为x和y,并使用多样性度量(shannon)绘制为轮廓但我不断得到以下错误,我不明白为什么......
Error in if (empty(new)) return(data.frame()) :
missing value where TRUE/FALSE needed
Run Code Online (Sandbox Code Playgroud)
我的代码是:
all_merge <-read.table("test.txt", header=TRUE)
p <- ggplot(all_merge, aes(NMDS1, NMDS2, z = shannon))
p + geom_contour()
Run Code Online (Sandbox Code Playgroud)
我的数据集是:
NMDS1 NMDS2 shannon
-0.287555952 -0.129887595 9.516558582
-0.314104852 -0.048655648 8.985087924
-0.214910534 -0.127167065 8.928241917
-0.341295065 -0.296282805 8.315476782
-0.470025718 0.083835083 8.494348157
-0.429386114 0.044064347 8.669813919
-0.427608469 0.124631936 8.15886319
-0.584412991 0.257278736 8.469688185
-0.436526047 -0.070633108 8.496878956
-0.584707076 0.120411579 8.319057817
0.183493022 0.445239412 5.611249955
0.172968855 0.583787121 5.728358304
-0.404838098 -0.0271276 8.679667562
-0.458718755 -0.05638174 8.714026645
0.458621093 -0.186746574 8.094002558
1.148457698 0.044192391 6.058046032
0.346825668 …Run Code Online (Sandbox Code Playgroud) 我写了一个小循环来找出哪个'bin'是一个数字,但我觉得它是相当pythonic而不是R.是否有更合适的方法来做到这一点,还是正常?
binLimits <- seq(0, 70, 10)
binNames <- c("A","B","C","D","E","F","G")
pos <- 45
# Find which bin pos is in
n <-0
for (i in binLimits){
if (pos < i){
pos.bin <- binNames[n]
break
}
n <- n+1
}
print (pos)
[1] "E"
Run Code Online (Sandbox Code Playgroud)
我很感激任何建议!