Converting row names into one columns in R and export to txt file -
i have multiple same names in row different dates , values corresponding it. want consolidate rows , make columns date , value. idea how in r? (i m learing r)
id date value 62 17/03/2008 1 62 29/09/2008 9 62 01/01/2009 0 66 01/04/2009 6 66 29/06/2009 3 66 30/09/2009 5 75 01/01/2010 6 75 01/04/2010 0 91 01/07/2010 8 91 28/09/2010 0
i want convert below
62 62 66 66 75 75 17/03/2008 1 01/04/2009 6 01/01/2010 6 29/09/2008 9 29/06/2009 3 01/04/2010 0 01/01/2009 0 30/09/2009 5
once done, want write output files groups(e.g. 62, 66, 75) in txt format name of txt file group names prefix 'a'(e.g. 62a.txt, 66a.txt, 75a.txt). have long dataset hence sort of looping has done.
what kind of output want? want split
data according id? return list entry each id. here's data.frame
, reproducible example. similarly, should provide structure of desired output.
df <- structure(list(id = c(62l, 62l, 62l, 66l, 66l, 66l, 75l, 75l, 91l, 91l), date = structure(c(6l, 9l, 1l, 3l, 8l, 10l, 2l, 4l, 5l, 7l), .label = c("01/01/2009", "01/01/2010", "01/04/2009", "01/04/2010", "01/07/2010", "17/03/2008", "28/09/2010", "29/06/2009", "29/09/2008", "30/09/2009"), class = "factor"), value = c(1l, 9l, 0l, 6l, 3l, 5l, 6l, 0l, 8l, 0l)), .names = c("id", "date", "value"), class = "data.frame", row.names = c(na, -10l))
this think want do:
split(df, df[,"id"]) split(df[,c("date", "value")], df[,"id"])
Comments
Post a Comment