I have a dataset that I am trying to reshape as wider
The original dataset is something like this
#df
Cell_line Gene AF
COLO320 MYC 0.5
COLO320 KRAS 0.4
H524 MYC 0.6
H524 KRAS 0.5
Expected is something like this:
**Cell_line** **MYC** **KRAS**
COLO320 0.5 0.4
H524 0.6 0.5
I don't want to lose any of my values so what I did is the following:
df1 = df %>% pivot_wider(names_from = Gene, values_from = AF, values_fn = list)
However I was getting a "dbl" as a list in the column values so I added a unnest():
df1 = df %>% pivot_wider(names_from = Gene, values_from = AF, values_fn = list) %>% unnest(cols = everything())
However, I am getting the following error example :
Error in unnest():
In row 8, can't recycle input of size 4 to size 2.
Anybody knows what is the solution?
My aim at the end is to reshape the data wider without losing the values.