我正在尝试使用R
在此示例csv文件中找到weight
列的中位数。但是代码没有返回任何结果。问题在哪里?
diabets <- read.csv ("https://hbiostat.org/data/repo/diabetes.csv")
median (diabets$weight)
然后在找到中位数之后,我需要打印权重低于这个中位数的女性。我该怎么做呢?
Please NO extra libraries.
na.rm = TRUE
参数将找到忽略NA
的中位数权重中有一个NA
sum(is.na(diabetes$weight))
[1] 1
Andmedian(diabetes$weight, na.rm = TRUE)
return 172.5 so,
diabetes[diabetes$gender== "female" & diabetes$weight < 172.5, ]
将打印体重低于该中位数的女性。
<标题>添加med <- median(diabetes$weight, na.rm = TRUE)
diabetes[(diabetes$gender== "female" & diabetes$weight < med), ]
或
diabetes[(diabetes$gender== "female" & diabetes$weight < median(diabetes$weight, na.rm = TRUE)), ]
标题>library(dplyr)
diabets %>%
filter(gender == "female") %>%
filter(weight < median(weight, na.rm = TRUE))
# A tibble: 123 x 19
id chol stab.glu hdl ratio glyhb location age gender height weight frame bp.1s bp.1d
<int> <int> <int> <int> <dbl> <dbl> <chr> <int> <chr> <int> <int> <chr> <int> <int>
1 1000 203 82 56 3.60 4.31 Buckingh~ 46 female 62 121 medi~ 118 59
2 1024 242 82 54 4.5 4.77 Louisa 60 female 65 156 medi~ 130 90
3 1030 238 75 36 6.60 4.47 Louisa 27 female 60 170 medi~ 130 80
4 1031 183 79 46 4 4.59 Louisa 40 female 59 165 medi~ NA NA
5 1036 213 83 47 4.5 3.41 Louisa 33 female 65 157 medi~ 130 90
6 1271 228 66 45 5.10 4.61 Buckingh~ 24 female 61 113 medi~ 100 70
7 1277 179 80 92 1.90 4.18 Buckingh~ 41 female 72 118 small 144 112
8 1282 254 84 52 4.90 4.52 Buckingh~ 43 female 62 145 medi~ 125 70
9 1317 136 81 51 2.70 4.58 Buckingh~ 22 female 66 160 large 105 85
10 1321 218 68 46 4.70 3.89 Buckingh~ 52 female 62 170 medi~ 142 79
# ... with 113 more rows, and 5 more variables: bp.2s <int>, bp.2d <int>, waist <int>,
# hip <int>, time.ppn <int>