[R] making dataframes

From: pelt <pelt_at_knmi.nl>
Date: Wed, 16 Mar 2011 14:28:29 +0000


Dear all,

I have a dataframe which looks like this (dummy):

date<-c("jan", "feb", "mar", "apr", "may", "june", "july",

"aug","sep","oct","nov","dec")
col1<-c(8.2,5.4,4.3,4.1,3.1,2.5,1.1,4.5,3.2,1.9,7.8,6.5)
col2<-c(3.1,2.3,4.7,6.9,7.5,1.1,3.6,8.5,7.5,2.5,4.1,2.3)
dum<-data.frame(cbind(date,col1,col2))
dum

   date col1 col2

1   jan  8.2  3.1
2   feb  5.4  2.3
3   mar  4.3  4.7
4   apr  4.1  6.9
5   may  3.1  7.5
6  june  2.5  1.1
7  july  1.1  3.6
8   aug  4.5  8.5
9   sep  3.2  7.5
10  oct  1.9  2.5
11  nov  7.8  4.1
12  dec  6.5  2.3

I would like to convert this data.frame into something that looks like this:

   date rainfall category

1   jan  8.2  col1
2   feb  5.4  col1
3   mar  4.3  col1
4   apr  4.1  col1
5   may  3.1  col1
6  june  2.5  col1
7  july  1.1  col1
8   aug  4.5  col1
9   sep  3.2  col1
10  oct  1.9  col1
11  nov  7.8  col1
12  dec  6.5  col1

1 jan 3.1 col2
2 feb 2.3 col2
3 mar 4.7 col2
4   apr   6.9 col2
5   may   7.5 col2
6  june   1.1 col2

7 july 3.6 col2
8 aug 8.5 col2
9 sep 7.5 col2
10  oct  2.5 col2
11  nov  4.1 col2
12  dec  2.3 col2

So the column-names become categories. The dataset is rather large with many columns and a lengthy date-string. Is there an easy way to do this?

Thank you for your help,

Kind regards,

Saskia van Pelt



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 16 Mar 2011 - 14:33:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Mar 2011 - 00:00:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive