简体   繁体   English

在嵌套并使用来自 tidyverse 的 map 之后,心理 package 的所有描述性结果有多不可靠?

[英]After nesting and using map from tidyverse, how unnest all descriptive results from psych package?

I have a dataset with quest and several topics .我有一个包含quest和几个topics的数据集。 After applying the "describe" function (from the psych package), how can I list all results in a convenient way?应用“描述”function(来自 psych 包)后,如何以方便的方式列出所有结果?

The results I've got:我得到的结果:

结果

The desired output is something like that:所需的 output 是这样的: 在此处输入图像描述

ds <- data.frame(quest = c(2,4,6,8), math_sum = rnorm(100,10,1), science_sum = rnorm(100,8,1))

    ds %>% 
        select(quest, ends_with("sum")) %>% 
        pivot_longer(-quest) %>% 
        nest_by(quest, name) %>% 
        mutate(x=list(map(data, ~psych::describe(.)))) %>% 
        unnest(-data)

You could use unnest_wider() :您可以使用unnest_wider()

library(tidyverse)

ds %>% 
  select(quest, ends_with("sum")) %>% 
  pivot_longer(-quest) %>% 
  nest_by(quest, name) %>% 
  mutate(x=list(map(data, ~psych::describe(.)))) %>% 
  unnest_wider(x) %>% 
  unnest_wider(value)

This returns这返回

# A tibble: 8 x 16
  quest name          data  vars     n  mean    sd median trimmed   mad   min   max
  <dbl> <chr>   <list<tib> <dbl> <dbl> <dbl> <dbl>  <dbl>   <dbl> <dbl> <dbl> <dbl>
1     2 math_s~   [25 x 1]     1    25 10.3  1.22   10.1    10.3  0.963  7.96 12.9 
2     2 scienc~   [25 x 1]     1    25  7.55 1.00    7.48    7.56 1.19   5.49  9.22
3     4 math_s~   [25 x 1]     1    25  9.59 0.998   9.50    9.58 0.858  7.31 11.6 
4     4 scienc~   [25 x 1]     1    25  8.07 1.28    8.24    8.01 1.70   6.13 10.6 
5     6 math_s~   [25 x 1]     1    25  9.85 0.932   9.79    9.79 0.929  8.50 11.8 
6     6 scienc~   [25 x 1]     1    25  7.80 0.907   7.81    7.79 0.959  6.03  9.69
7     8 math_s~   [25 x 1]     1    25 10.2  1.19   10.4    10.2  1.06   8.09 13.1 
8     8 scienc~   [25 x 1]     1    25  8.01 0.923   7.88    7.99 0.908  6.23  9.87
# ... with 4 more variables: range <dbl>, skew <dbl>, kurtosis <dbl>, se <dbl>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用tidyverse与psych软件包从不同的数据集/数据库获取raw_alpha值 - Using tidyverse to get raw_alpha values with the psych package from different datasets / databases 使用 psych::describe() 在 csv 中打印变量名称 - Print variable names in csv using psych::describe() 使用R中的心理包对“ timeSeries”结构数据进行描述性统计 - Descriptive Statistics of “timeSeries” structure data using psych package in R 如何从 psych 包中的 describeBy 的输出中排除变量? - How to exclude variables from the output of describeBy in the psych package? 心理包中的describe()没有提供完整的描述 - describe() from psych package not providing full descriptives 如何使用 tidyverse 包消除所有组中具有 NA 的相同行? - How to eliminate the same rows with NA in all groups using the tidyverse package? 使用str_extract_all和unnest但从NA中丢失行 - Using str_extract_all and unnest but losing rows from NA 如何使用 tidyverse 从测试结果中计算百分比分数? - How can I calculate the percentage score from test results using tidyverse? 使用从 R 的 tidyverse 'map' 的 output 中提取的 lm 使用 'segmented' 时出错 - Error using 'segmented' with lm extracted from output of tidyverse 'map' in R 如何使用 psych 包提取所有观察的主成分值 - How do I extract the principal component`s values of all observations using psych package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM