我有一个2841*7的长数据,想使用pivot_wider变为宽数据,希望结果是85行,但结果为317行,还包含很多缺失值。
x1 <- x %>% select(-admission_date) %>% pivot_wider(names_from = type,values_from = result)
#> Error in x %>% select(-admission_date) %>% pivot_wider(names_from = type, : could not find function "%>%"
dput(x)
#> Error in dput(x): object 'x' not found
sessionInfo()
#> R version 4.2.1 (2022-06-23 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=Chinese (Simplified)_China.utf8
#> [2] LC_CTYPE=Chinese (Simplified)_China.utf8
#> [3] LC_MONETARY=Chinese (Simplified)_China.utf8
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=Chinese (Simplified)_China.utf8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] withr_2.5.0 digest_0.6.29 lifecycle_1.0.1 magrittr_2.0.3
#> [5] reprex_2.0.2 evaluate_0.15 highr_0.9 stringi_1.7.6
#> [9] rlang_1.0.6 cli_3.3.0 rstudioapi_0.13 fs_1.5.2
#> [13] rmarkdown_2.18 tools_4.2.1 stringr_1.4.0 glue_1.6.2
#> [17] xfun_0.31 yaml_2.3.5 fastmap_1.1.0 compiler_4.2.1
#> [21] htmltools_0.5.3 knitr_1.39
<sup>Created on 2023-02-05 with reprex v2.0.2</sup>
按照发帖指引写的,不知道对不对