gpt4 book ai didi

r - 为什么 summary 和 class 方法在 R 中的 data.frame 类型上不一致?

转载 作者:行者123 更新时间:2023-12-02 08:39:19 26 4
gpt4 key购买 nike

<分区>

这是设置:

mydf<-structure(list(weight = c(1.34288799762726, 1.18884372711182, 
1.15979790687561, 1.34288799762726, 1.08285343647003, 1.07932889461517,
1.28913342952728, 1.211909532547, 1.03438591957092, 1.22719633579254
), RespID = c(3182, 3183, 3184, 3185, 3186, 3187, 3188, 3189,
3190, 3191), b1 = structure(c(1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L,
2L, 2L), .Label = c("Mand", "Kvinde"), class = "factor")), .Names = c("weight",
"RespID", "b1"), row.names = c(NA, 10L), class = "data.frame")

现在调用 summary 将生成以下输出:

summary(mydf)
# weight RespID b1
# Min. :1.034 Min. :3182 Mand :4
# 1st Qu.:1.102 1st Qu.:3184 Kvinde:6
# Median :1.200 Median :3186
# Mean :1.196 Mean :3186
# 3rd Qu.:1.274 3rd Qu.:3189
# Max. :1.343 Max. :3191

同时 apply 给出另一个结果:

apply(mydf, 2, class)
# weight RespID b1
#"character" "character" "character"

因此,根据应用,我的 data.frame 中的每一列都属于“字符”类,我知道这是错误的。不过,总结是正确的。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com