我的數據是這樣的發現在每列
df <- structure(list(A = c(0.91971, 0.61566, 0.78723, 1.038, 0.65656,
0.9448, NaN, 1.1353, 0.82117, 0.15673), RA = c(NaN, 10, NaN,
200, NaN, 0.2, NaN, NaN, 30, NaN), B = c(100, 0.2, NaN, 400,
NaN, NaN, 20, NaN, 3, NaN), CM = c(NaN, NaN, 77, NaN, 2, NaN,
0.02, NaN, 0.8, 1), D = c(6, 5, NaN, NaN, NaN, 0.1, 0.5, NaN,
NaN, NaN)), .Names = c("A", "RA", "B", "CM", "D"), row.names = c(NA,
-10L), class = "data.frame")
# A RA B CM D
#1 0.91971 NaN 100.0 NaN 6.0
#2 0.61566 10.0 0.2 NaN 5.0
#3 0.78723 NaN NaN 77.00 NaN
#4 1.03800 200.0 400.0 NaN NaN
#5 0.65656 NaN NaN 2.00 NaN
#6 0.94480 0.2 NaN NaN 0.1
#7 NaN NaN 20.0 0.02 0.5
#8 1.13530 NaN NaN NaN NaN
#9 0.82117 30.0 3.0 0.80 NaN
#10 0.15673 NaN NaN 1.00 NaN
我想知道有多少元素的不同範圍內的值的個數在於:
[1, 5)
之間[0, 1)
之間[5, 10)
- and
>= 10
所以輸出應該類似於例如第一列
ColumnA columnRA columnB columnCM columnD
0 to 1 7 1 1 2 2
1 to 5 2 0 1 2 0
5 to 10 0 0 0 0 2
above 10 0 3 3 1 0
我試圖用sapply
但我無法弄清楚如何做到這一點
count0-1 <-sapply(x, function(x) sum(length(which(x >0 & <1))))
'count0_1 < - sapply(DF,函數(x)的總和(長度(其(X> 0&X <1))))' – Sumedh
請提open'和'close'的'的條件。 – user2100721