on-internet
← Community

Converting two couple 2 columns into a long format dataset: how to do?

Stack Overflow ·

I have tried to manipulate the original dataset I had as follows. db%>% mutate(GROUP = fct_recode(GROUP, CONTROL = "CONTROLLO")) %>% to_long(keys = c("tests0", "tests7"), values =c("score0", "score7"), grep("T0$", names(.), value = TRUE), grep("T7$", names(.), value = TRUE)) %>% as_tibble %>% mutate(Gender = factor(Gender, levels = c(1, 0), labels = c("M", "F")), across(c(tests0, tests7), factor)) And I have obtained the following dataset # A tibble: 200 × 13 subj GROUP Gender Age EX testa_score_T1 testb_score_T1 testc_score_T1 testd_score_T1 tests0 <chr> <fct> <fct> <int> <int> <dbl> <dbl> <d

Comments

Sign in or sign up to comment and upvote.

No comments yet.