0

I searched but I could not find an answer for a question similar to this. I am working with a data set that has a column with metadata about the remaining data columns. I want to split that original data set into a new data frame looking only at one of the variables with column headers from the metadata column. For example:

id  metadata var1 var2 var3
001 A        1    1    5
002 B        3    2    4
003 A        2    4    7
004 C        8    4    1

and then I want the output to look something like this with only the values from the var1 column:

id   var1.A   var1.B  var1.C
001  1   
002           3
003  2
004                   8

and then I would write loop to export that to a csv and propagate it down the rest of the columns for a different file for each.

thejuanald
  • 27
  • 5
  • It is a reshpae from long to wide `dcast(df, id ~ paste0("var", metadata), value.var = 'var1', fill = 0)` – akrun Mar 16 '18 at 15:59
  • 1
    Thank you, @akrun that was much easier than I was making it and I was looking at the completely wrong function – thejuanald Mar 16 '18 at 16:22

0 Answers0