Hello,
This is my very first question here.
I want to separate the collapsed column into multiple rows. The data:
x = 1:3,
y = c("a", "d,e,f", "g,h"),
z = c("A", "D,E", "G"), stringsAsFactors = FALSE
)```
Then I use:
``` separate_rows(df,y,z) ```
And I got the following error:
> separate_rows(df,y,z)
Error: All nested columns must have the same number of elements.
Call `rlang::last_error()` to see a backtrace
I understand why the error, since there are not the same number of elements in the nested columns.
The desired output would be
``` df2 <- data.frame(
x = c(1, rep(2,3), rep(3,2)),
y = c("a","d","e","f","g","h"),
z = c("A","D","E",NA,"G",NA), stringsAsFactors = FALSE
)
print(df2) ```
> df2
x y z
1 1 a A
2 2 d D
3 2 e E
4 2 f <NA>
5 3 g G
6 3 h <NA>
I'm using the tidyr version 0.8.3 and I cannot upgrade it (policy of the company I work).
Can you help me,
Thanks in advance.