Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从R中的列中找到前n个最小值?_R - Fatal编程技术网

如何从R中的列中找到前n个最小值?

如何从R中的列中找到前n个最小值?,r,R,我有一个这样的命令,它在e$V2列中找到一个最小值 EQTLs<-s[s$POS==as.numeric(e[tail(which(e$V2 == min(e$V2)), 1),1]),] EQTLs我不能完全理解第一位代码的逻辑,但它似乎旨在提取名为s的数据帧的行,其中名为V2的特定列至少位于名为e的不同数据帧中。(我无法确定POS列应该扮演什么角色。因此,我假设您想要10行(s),其中e$V2假定其10个最低值。这将很简单: EQTLs <- s[ order(e$V2)[1

我有一个这样的命令,它在e$V2列中找到一个最小值

EQTLs<-s[s$POS==as.numeric(e[tail(which(e$V2 == min(e$V2)), 1),1]),]

EQTLs我不能完全理解第一位代码的逻辑,但它似乎旨在提取名为
s
的数据帧的行,其中名为
V2
的特定列至少位于名为
e
的不同数据帧中。(我无法确定
POS
列应该扮演什么角色。因此,我假设您想要10行(s),其中
e$V2
假定其10个最低值。这将很简单:

 EQTLs <- s[ order(e$V2)[1:10] , ]
请提供一个。我提供的链接将告诉您如何。干杯。提供
dput(head(s,20))
dput(head(e,20))
的输出,而不是复制/粘贴它们。我强烈建议您阅读我提供的链接,它可以帮助您在将来提出更好的问题。
 EQTLs <- s[ order(e$V2)[1:10] , ]
  dput( s[ order(s$V2)[1:20]  , ] ) # rows of s with 20 lowest V2 values
  dput( e[ order(s$V2)[1:20]  , ] ) # reproducible version of e with same row nums