#> user_id domain indicator `Time 1` `Time 3` `Time 4` #> `summarise()` regrouping output by 'user_id', 'Timepoint', 'domain' (override with `.groups` argument) Group_by(user_id, Timepoint, domain, indicator) %>%Ĭur_data() %>% add_row(score = mean(score). Mutate(domain = (as.numeric(indicator) - 1) %/% 4) %>% Same basic idea as in answer, but simplified a bit with new dplyrġ.0.0 features that allow summarise() to increase the row count: library(tidyverse) Ultimately, I would like a table like this per user (where the NAs are the appropriate means) (Note: This one is for Bob - he didn't have scores for time 1 or time 2): structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, Time4 = mean, mean, mean, mean, mean, mean, mean, mean) %>% Time3 = mean, mean, mean, mean, mean, mean, mean, mean, Time2 = mean, mean, mean, mean, mean, mean, mean, mean, Summarise(Time1 = mean, mean, mean, mean, mean, mean, mean, mean, Group_by(user_id,indicator,Timepoint) %>% "George", "George", "George", "George", "George", "George", "George", Also, some users (read several) will not have values at all timepoints. I have attempted this with tidyverse and would appreciate help. Thus, each teacher_id's outputted table should be a 10 by 4. I would also like the outputted tables to have four columns, one per timepoint. The mean of domain 0 is the mean of indicators 1-4, and the mean of domain 1 is the mean of indicators 5-8. I would like the table to have 10 rows, 8 of which are the means of the indicators 1-8 per timepoint, and the other two are domain means per timepoint. I need to produce a table for each unique user_id. The number of observants is much larger than the data given below, but this tibble should be sufficient. quantile() was hard to use previously because it returns multiple values.I am trying to produce a table of mean scores for each participant in my tibble. To demonstrate this new flexibility in a more useful situation, let’s take a look at quantile(). This is a big change to summarise() but it should have minimal impact on existing code because it broadens the interface: all existing code will continue to work, and a number of inputs that would have previously errored now work. To put this another way, before dplyr 1.0.0, each summary had to be a single value (one row, one column), but now we’ve lifted that restriction so each summary can generate a rectangle of arbitrary size. (This isn’t very useful when used directly, but as you’ll see shortly, it’s really useful inside of functions.) Df %>% group_by ( grp ) %>% summarise ( tibble ( min = min ( x ), mean = mean ( x ))) #> `summarise()` ungrouping output (override with `.groups` argument) #> # A tibble: 2 x 3 #> grp min mean #> * #> 1 1 -2.69 -0.843 #> 2 2 -2.73 -0.434
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |