2012-06-12 10 views

答えて

23

使用max()TRUEに設定na.rm引数で:

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 
関連する問題