Last active
March 12, 2019 14:37
-
-
Save padpadpadpad/b3117f9a2fe9d14174f32e5f31a2f454 to your computer and use it in GitHub Desktop.
example of re-scaling some questionnaire data for Sarah
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load packages | |
| library(tidyr) | |
| library(dplyr) | |
| # load in data | |
| d <- read.csv('~/Desktop/orig_ratings.csv', stringsAsFactors = FALSE) | |
| # stack participants | |
| d_stack <- gather(d, 'participant', 'score', 2:ncol(d)) | |
| # group by each particpant, arrange by score and create a new column for scaled_score | |
| # new scale | |
| new_scale <- c(-3,-2,-2,-1,-1,-1,0,0,0,0,0,1,1,1,2,2,3) | |
| d_stack <- group_by(d_stack, participant) %>% | |
| arrange(score) %>% | |
| mutate(new_scale = new_scale) %>% | |
| ungroup() | |
| # create d again | |
| d_new <- select(d_stack, -score) %>% | |
| spread(., participant, new_scale) | |
| write.csv(d_new, 'put/this/somewhere.csv', row.names = FALSE) | |
| write.csv(d_stack, 'put/this/somewhere_else.csv', row.names = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment