我是 R 新手,我正在尝试做一些非常简单的事情。我已经加载了一个包含四列的 txt 文件,现在我想获取第二列的最小值。 这是我的代码:
## Choose the directory of the file
setwd("//Users//dkar//Desktop")
## Read the txt file
data<-read.table("export_v2.txt",sep="",header=T)
str(data)
## this command gives me the minimum for all 4 columns!!
a<-apply(data,2,min)
实际上,如果我想做这样的事情:min(data(:,2))。但我不知道如何在 R 中做到这一点。有帮助吗?
最佳答案
如果您需要特定列的最小值
min(data[,2])
注意:R 考虑 NA
最小值和最大值,因此如果您的列中有 NA,它们将返回:NA
。要补救,请使用:
min(data[,2], na.rm=T)
关于r - R中如何求某列的最小值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13762364/