【问题标题】:how to present results of k-mean in R?如何在 R 中呈现 k-mean 的结果?
【发布时间】:2021-09-19 09:56:53
【问题描述】:

我的代码如下:

act[,-c(1,2)]%>%
  mutate(Cluster = km$cluster) %>%
  group_by(Cluster) %>%
  summarise_all("mean")

这是结果。

# A tibble: 3 x 12
  Cluster sleep_PersonalActivity PaidWorking Studying Transport UnpaidWorking Socializing
    <int>                  <dbl>       <dbl>    <dbl>     <dbl>         <dbl>       <dbl>
1       1                   10.0       3.84      0        1.19           3.23       0.931
2       2                   11.1       2.07      1.62     1.12           1.43       0.918
3       3                   11.1       0.639     0        0.917          3.43       1.00 
# ... with 5 more variables: CivicReligious <dbl>, Sport <dbl>, ActiveLeisure <dbl>,
#   PassiveLeisure <dbl>, Others <dbl>

数据框有9个变量:

sleep_PersonalActivity、有偿工作、学习、交通、无偿工作、社交、公民宗教、运动、ActiveLeisure、PassiveLeisure、其他。

如何让 R 显示结果中的所有变量?我需要调整小标题的大小吗?如果是这样,我该怎么办?感谢大家的帮助。

【问题讨论】:

  • 是tibble打印设置。如果您View(output) 将看到所有列或使用as.data.frame 转换为data.frame

标签: r cluster-computing k-means


【解决方案1】:

这是因为tibbleprint 设置。我们可以将width指定为Inf

print(out, width = Inf)

在哪里

out <- act[,-c(1,2)]%>%
  mutate(Cluster = km$cluster) %>%
  group_by(Cluster) %>%
  summarise_all("mean")

View(out) 输出不会有任何问题,或者如果我们使用as.data.frame 转换为data.frame 不会有任何问题

【讨论】:

    猜你喜欢
    • 2021-12-13
    • 2018-03-20
    • 2019-01-25
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 2011-08-04
    相关资源
    最近更新 更多