2012-06-12 52 views

回答

23

使用max()na.rm參數設置爲TRUE

dat <- read.table(text=" 
    x1 x2 x3 
1 NA 4 1 
2 NA 3 NA 
3 4 NA 2 
4 NA 1 11 
5 NA 2 NA 
6 5 NA 1 
7 5 9 NA 
8 NA 2 NA", header=TRUE) 

獲取最大:

max(dat, na.rm=TRUE) 
[1] 11 
2

要查找列的總和,你可能想選擇不公開其第一;

max(unlist(myDataFrame$myColumn), na.rm = TRUE) 

Source

0

你可以寫專欄的最大功能,colMax

colMax <- function(data) sapply(data, max, na.rm = TRUE) 
樣本數據

使用colMax功能:

colMax(x) 
# x1  x2  x3 
# 5.0 9.0 11.0