Dear R Forum,
I have a data.frame as
df = data.frame(date = c(2013-04-15, 2013-04-14, 2013-04-13,
2013-04-12, 2013-04-11),
ABC_f = c(62.80739769,81.04525895,84.65712455,12.78237251,57.61345256),
LMN_d = c(21.16794336,54.6580401,63.8923307,87.59880367,87.07693716),
XYZ_p =
Hint:
nm - substring(names(df). 1,3)
gives the first 3 letters of the names, assuming this is the info
needed for classifying the names -- you were not explicit about this.
If some sort of pattern is used, ?grep may be what you need.
You can then pick columns from df by e.g. loopingt through
-
From: Katherine Gobin katherine_go...@yahoo.com
To: r-help@r-project.org
Cc:
Sent: Friday, April 26, 2013 9:21 AM
Subject: [R] Splitting data.frame and saving to csv files
Dear R Forum,
I have a data.frame as
df = data.frame(date = c(2013-04-15, 2013-04-14, 2013-04-13,
2013-04-12, 2013-04-11
...@yahoo.com
Cc: R help r-help@r-project.org
Sent: Friday, April 26, 2013 9:45 AM
Subject: Re: [R] Splitting data.frame and saving to csv files
Hi,
You can do this:
lst1-lapply(split(colnames(df)[-1],gsub(_.*,,colnames(df)[-1])),function(x)
{x1-cbind(date=df[,1],df[,x]);colnames(x1)[-1]- x;x1
4 matches
Mail list logo