Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

'df' must evaluate to column positions or names, not a list- pivot_wider

$
0
0

I have a df similar to this

ID    Concentration
 A          1
 A          2
 B          3
 B          4

and I would like the pivot the id's into columns with the values being the concentrations and missing values being filled with NAs. At first I tried just

pivot_wider(temp,names_from = Lab_ID, values_from = concentration, values_fill = NULL)%>% unnest()

but I was getting the error: Values in concentration are not uniquely identified; output will contain list-cols.

So I tried this

temp %>%
  group_by(Lab_ID) %>%
  mutate(rn = row_number()) %>%
  pivot_wider(temp,names_from = Lab_ID, values_from = concentration, values_fill = NULL)%>% unnest()

but now I am getting this error

Error: temp must evaluate to column positions or names, not a list


Viewing all articles
Browse latest Browse all 201839

Trending Articles