小编Tur*_*tle的帖子

创建具有来自单独表行的列特征的数据框

我有一个描述性的辅助表,其行指定变量的特征,其中varCat描述变量类别、rept所述类别的后续实现重复次数及其form数据格式:

\n
require(dplyr)\nrequire(tidyr)\nrequire(purrr)\n\ndescr <- tibble(\n  varCat = c("a", "b"),\n  rept = c(1, 3),\n  form = c("text", "num")\n)\ndescr\n#> # A tibble: 2 \xc3\x97 3\n#>   varCat  rept form \n#>   <chr>  <dbl> <chr>\n#> 1 a          1 text \n#> 2 b          3 num\n
Run Code Online (Sandbox Code Playgroud)\n

我想要获得的是以下(空)数据框:

\n
d\n#> # A tibble: 0 \xc3\x97 4\n#> # \xe2\x80\xa6 with 4 variables: a <chr>, b_1 <dbl>, b_2 <dbl>, b_3 <dbl>\n
Run Code Online (Sandbox Code Playgroud)\n

创建于 2022-09-27,使用reprex v2.0.2

\n

涉及两个步骤:

\n
    \n
  1. 辅助表var和 …

r dplyr purrr tidyverse

3
推荐指数
1
解决办法
90
查看次数

标签 统计

dplyr ×1

purrr ×1

r ×1

tidyverse ×1