Skip to content

Instantly share code, notes, and snippets.

@edgararuiz-zz
Created October 22, 2019 20:55
Show Gist options
  • Save edgararuiz-zz/f57e722db9f97a8de15ab1b72ea9712c to your computer and use it in GitHub Desktop.
Save edgararuiz-zz/f57e722db9f97a8de15ab1b72ea9712c to your computer and use it in GitHub Desktop.
library(tidyverse)
data <- tribble(
~id, ~rater1, ~rater2, ~rater3, ~rater4, ~rater5,
901,7,9,9,9,2,
902,9,9,9,9,9,
903,9,9,9,9,9,
"age",21,39,38,33,21,
"gender",1,2,2,2,2,
"language",1,2,1,1,1
)
new_data <- data %>%
select(contains("rater")) %>%
transpose() %>%
map(~as.double(.x)) %>%
set_names(data$id) %>%
map_dfc(~.x)
new_data
#> # A tibble: 5 x 6
#> `901` `902` `903` age gender language
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 7 9 9 21 1 1
#> 2 9 9 9 39 2 2
#> 3 9 9 9 38 2 1
#> 4 9 9 9 33 2 1
#> 5 2 9 9 21 2 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment