我試圖找出子集在R.子集,DAT [13:24.2]不回我的預期在這種情況下
我有一個命名爲Diet
和Bodyweight
兩列數據集。 行1:12
是對照觀測值,我想獲得對照組的Bodyweight
列的平均值。
所以我用這個:mean(dat[1:12,2])
然後我想找出多少不可控制的觀測(行13:24)均低於對照觀測(行1:12)的平均值。
所以我用這個: dat[dat[13:24,2] < mean(dat[1:12,2]), ]
這給了我這樣的:
Diet Bodyweight
3 chow 24.04
10 chow 20.10
12 chow 26.25
15 hf 22.80
22 hf 21.90
24 hf 20.73
但我期待它返回這樣的事情,其中不包括行1:12:
Diet Bodyweight
15 hf 22.80
22 hf 21.90
24 hf 20.73
我該如何做到這一點?
*編輯:dput()結果:
> dput(dat)
structure(list(Diet = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("chow", "hf"), class = "factor"), Bodyweight = c(21.51,
28.14, 24.04, 23.45, 23.68, 19.79, 28.4, 20.98, 22.51, 20.1,
26.91, 26.25, 25.71, 26.37, 22.8, 25.34, 24.97, 28.14, 29.58,
30.92, 34.02, 21.9, 31.53, 20.73)), .Names = c("Diet", "Bodyweight"
), class = "data.frame", row.names = c(NA, -24L))
**請張貼with'dput()'** – smci 2015-01-27 01:26:12