将作为多列标题的标题列转换为仅包含多个列的标题

时间:2020-09-02 18:24:09

标签: r dplyr tidyverse

使用dplyr 1.0.0,可以使用dplyr::group_by()dplyr::summarise()进行以下操作:

tibble(
      x = rnorm(100)
    , y = rnorm(100)
    , z = rep(c(1,2),each=50)
) %>%
    dplyr::group_by(z) %>%
    dplyr::summarize(
        value = as_tibble(prcomp(cur_data())$x)
        , .groups = 'drop'
    ) ->
    out

out现在有一个名为value的列,它本身是一个带有两列的小标题:

> print(out)
# A tibble: 6 x 2
      z value$PC1   $PC2
  <dbl>     <dbl>  <dbl>
1     1    -0.212  3.16 
2     1    -1.02   0.978
3     1    -0.328 -0.419
4     1     1.17  -0.341
5     1    -1.68  -0.775
6     1     0.266 -0.398

> str(out,max=2)
tibble [100 × 2] (S3: tbl_df/tbl/data.frame)
 $ z    : num [1:100] 1 1 1 1 1 1 1 1 1 1 ...
 $ value: tibble [100 × 2] (S3: tbl_df/tbl/data.frame)

然后我将如何将单个value列转换为多列,value标题中的每一列将转换为多列?

1 个答案:

答案 0 :(得分:1)

您可以 C:\PROJECTS\NEWS2\Temp\gradleOut\launcher\build\intermediates\bundle_manifest\release\processReleaseManifest\bundle-manifest\AndroidManifest.xml:58: error: attribute android:requestLegacyExternalStorage not found. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) 将其pull打开:

bind