I want to reshape a large data set i have from a long to a wide format. Currently my data set is formed as follows:
df <- structure(list(Politician = c("1", "2", "3", "k", "1", "2", "3",
"k"), country = c("uk", "nl", "ro", "z", "uk", "nl", "ro", "z"
), variables = c(NA, NA, NA, NA, NA, NA, NA, NA), voteid = c(12,
12, 12, 12, 13, 13, 13, 13), votedecision = c(1, 9, 9, 1, 3,
2, 0, 9)), row.names = c(NA, -8L), class = c("tbl_df", "tbl",
"data.frame"))
Now i want to reshape this votematrix as follows:
# A tibble: 3 x 8
Politician counrty variables vote12 vote13 vote14 vote15 ...
<int> <chr> <lgl> <dbl> <dbl> <dbl> <dbl> <chr>
1 1 uk NA 1 3 1 9 ...
2 2 nl NA 9 2 2 0 ...
3 3 ro NA 9 0 1 2 ...
The dataset contains 8 variables and over 9 million observations. I'm pretty new to Rstudio, so thus far i've just tried a bunch of codes that i found on the internet. For example:
ep.new = cast(ep, mepid~voteid, value = "votedecision")
when I run that order it takes a long time and then i get the a warning: Aggregation requires fun.aggregate: length used as default
Does anyone have any tips or suggestions how to solve my problem(s)?
*there are several more variables containing information about the specific politicians.