I am thoruoghly researching this question on SO from the very morning. Original dataset has more than 1000 rows. My global goal is to extract particular columns to run an OLS-regression.
I selected the columns I need and transformed it to a wide format using pivot_wider
. In the transformed table I have 5 columns which represent indicators name. The rows are respondets' ids, the values are answers.
The problem is that after the transformation the values mutated into the nested objects. I tried to resolve this issue on a sample dataset using unnest(cols = everything())
. And it works fine:
examp_df <- tibble(
seance = rep(1:5, each = 5),
ind = rep(inds, 5),
ind_name = rep(inds_name, 5),
answer = list(rep(rnorm(5, 0.7, 1), 5))
)
examp_df_wide <- examp_df %>%
pivot_wider(id_cols = seance,
names_from = ind_name,
values_from = answer)
exmap_df_wide <- examp_df_wide %>%
unnest(cols = everything())
But when I try it on my original dataset, I receive an error about incompatiability of length. And then I do not understand how unnest
works.
Here's the dataset which I have problems with. How can I unnest the data?
The list of sources that I have researched:
Original data is here.
The code fot the original data is the following:
data_all <- data_all %>%
pivot_wider(id_cols = seance_id,
names_from = ind_name,
values_from = criteria_answ)
> data_all <- data_all %>%
+ unnest(cols = everything())
Error: Incompatible lengths: 4, 5.
Run `rlang::last_error()` to see where the error occurred.