Dear users, I have several columns of data (each column containing monthly data for a particular year from january - december) . I would wish to combine the columns to get a Single column of continuous data as shown in (b) below. I have read this data as table in R (a) Data example Year 1903 1904 1905 1906 Jan 125.0 30.0 113.0 5.0 Feb 128.0 100.0 70.0 388.0 Mar 155.0 79.0 230.0 323.0 Apr 199.0 89.0 104.0 199.0 May 215.0 96.0 50.0 162.0 Jun 228.0 16.0 41.0 154.0 Jul 26.0 49.0 63.0 35.0 Aug 19.0 118.0 55.0 180.0 Sep 94.0 92.0 57.0 161.0 Oct 150.0 47.0 42.0 142.0 Nov 18.0 118.0 160.0 81.0 Dec 128.0 234.0 344.0 76.0 (b)Single column : Jan 125.0 Feb 128.0 Mar 155.0 Apr 199.0 May 215.0 Jun 228.0 Jul 26.0 Aug 19.0 Sep 94.0 Oct 150.0 Nov 18.0 Dec 128.0 Jan 30.0 Feb 100.0 Mar 79.0 Apr 89.0 May 96.0 Jun 16.0 Jul 49.0 Aug 118.0 Sep 92.0 Oct 47.0 Nov 118.0 Dec 234.0 Jan 113.0 Feb 70.0 Mar 230.0 Apr 104.0 May 50.0 Jun 41.0 Jul 63.0 Aug 55.0 Sep 57.0 Oct 42.0 Nov 160.0 Dec 344.0 Jan 5.0 Feb 388.0 Mar 323.0 Apr 199.0 May 162.0 Jun 154.0 Jul 35.0 Aug 180.0 Sep 161.0 Oct 142.0 Nov 81.0 Dec 76.0 Thanks ---------------------------- ZABLONE OWITI GRADUATE STUDENT College of Atmospheric Science Nanjing University of Information, Science and Technology Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China Tel: +86-25-58731402 Fax: +86-25-58731456 Mob. 15077895632 Website: www.nuist.edu.cn =================================================== [[alternative HTML version deleted]]
Gabor Grothendieck
2010-May-27 02:51 UTC
[R] How to combine data columns to a single column
This is a time series so its best to represent it as such using a ts object. Below tt is the vector of data you asked for and tt.ts is the same vector converted into a ts series: Lines <- "Year 1903 1904 1905 1906 Jan 125.0 30.0 113.0 5.0 Feb 128.0 100.0 70.0 388.0 Mar 155.0 79.0 230.0 323.0 Apr 199.0 89.0 104.0 199.0 May 215.0 96.0 50.0 162.0 Jun 228.0 16.0 41.0 154.0 Jul 26.0 49.0 63.0 35.0 Aug 19.0 118.0 55.0 180.0 Sep 94.0 92.0 57.0 161.0 Oct 150.0 47.0 42.0 142.0 Nov 18.0 118.0 160.0 81.0 Dec 128.0 234.0 344.0 76.0" # read into data frame DF <- read.table(textConnection(Lines), header = TRUE, check.names = FALSE) tt <- c(as.matrix(DF)) # create ts object tt.ts st <- as.numeric(names(DF)[2]) # 1903 tt.ts <- ts(tt, freq = 12, start = st) plot(tt.ts) On Wed, May 26, 2010 at 10:30 PM, Zablone Owiti <zowiti at ncst.go.ke> wrote:> Dear users, > > I have several columns of data (each column containing monthly data for a > particular year from january - december) . I would wish ?to combine ?the > columns to get a Single column of continuous data as shown in (b) below. I > have read this data as table in R > (a) Data example > > Year ? ? 1903 ? ?1904 ? ?1905 ? ?1906 ? ?Jan ? ? 125.0 ? 30.0 ? ?113.0 ? 5.0 ? ? Feb > ? ? ? ? 128.0 ? 100.0 ? 70.0 ? ?388.0 ? Mar ? ? 155.0 ? 79.0 ? ?230.0 ? 323.0 ? Apr > 199.0 ? ?89.0 ? ?104.0 ? 199.0 ? May ? ? 215.0 ? 96.0 ? ?50.0 ? ?162.0 ? Jun > 228.0 ? ?16.0 ? ?41.0 ? ?154.0 ? Jul ? ? 26.0 ? ?49.0 ? ?63.0 ? ?35.0 ? ?Aug ? ? 19.0 > ? ? ? ? 118.0 ? 55.0 ? ?180.0 ? Sep ? ? 94.0 ? ?92.0 ? ?57.0 ? ?161.0 ? Oct ? ? 150.0 > 47.0 ? ? 42.0 ? ?142.0 ? Nov ? ? 18.0 ? ?118.0 ? 160.0 ? 81.0 ? ?Dec ? ? 128.0 > 234.0 ? ?344.0 ? 76.0 > > (b)Single column : > > Jan ? ? ?125.0 ? Feb ? ? 128.0 ? Mar ? ? 155.0 ? Apr ? ? 199.0 ? May ? ? 215.0 ? Jun > ? ? ? ? 228.0 ? Jul ? ? 26.0 ? ?Aug ? ? 19.0 ? ?Sep ? ? 94.0 ? ?Oct ? ? 150.0 ? Nov ? ? 18.0 > Dec ? ? ?128.0 ? Jan ? ? 30.0 ? ?Feb ? ? 100.0 ? Mar ? ? 79.0 ? ?Apr ? ? 89.0 ? ?May > 96.0 ? ? Jun ? ? 16.0 ? ?Jul ? ? 49.0 ? ?Aug ? ? 118.0 ? Sep ? ? 92.0 ? ?Oct ? ? 47.0 > Nov ? ? ?118.0 ? Dec ? ? 234.0 ? Jan ? ? 113.0 ? Feb ? ? 70.0 ? ?Mar ? ? 230.0 ? Apr > ? ? ? ? 104.0 ? May ? ? 50.0 ? ?Jun ? ? 41.0 ? ?Jul ? ? 63.0 ? ?Aug ? ? 55.0 ? ?Sep ? ? 57.0 > Oct ? ? ?42.0 ? ?Nov ? ? 160.0 ? Dec ? ? 344.0 > > Jan ? ? ?5.0 ? ? Feb ? ? 388.0 ? Mar ? ? 323.0 ? Apr ? ? 199.0 ? May ? ? 162.0 ? Jun > 154.0 ? ?Jul ? ? 35.0 ? ?Aug ? ? 180.0 ? Sep ? ? 161.0 ? Oct ? ? 142.0 ? Nov ? ? 81.0 > Dec ? ? ?76.0 > > Thanks > > ---------------------------- > ?ZABLONE OWITI > ?GRADUATE STUDENT > College of Atmospheric Science > Nanjing University of Information, Science and Technology > Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China > ?Tel: +86-25-58731402 > Fax: +86-25-58731456 > Mob. 15077895632 > Website: ?www.nuist.edu.cn > ===================================================> > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Thanks Dr. Gabor and Dr. Murphy, your directions worked . ---------------------------- ZABLONE OWITI GRADUATE STUDENT College of Atmospheric Science Nanjing University of Information, Science and Technology Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China Tel: +86-25-58731402 Fax: +86-25-58731456 Mob. 15077895632 Website: www.nuist.edu.cn =================================================== ---------------------------------------- From: "Dennis Murphy" <djmuser@gmail.com> Sent: Thursday, May 27, 2010 4:09 PM To: "Gabor Grothendieck" <ggrothendieck@gmail.com> Subject: Re: [R] How to combine data columns to a single column Hi: I assume you meant tt <- c(as.matrix(DF[, -1])) Regards, Dennis On Wed, May 26, 2010 at 7:51 PM, Gabor Grothendieck <ggrothendieck@gmail.com> wrote: This is a time series so its best to represent it as such using a ts object. Below tt is the vector of data you asked for and tt.ts is the same vector converted into a ts series: Lines <- "Year 1903 1904 1905 1906 Jan 125.0 30.0 113.0 5.0 Feb 128.0 100.0 70.0 388.0 Mar 155.0 79.0 230.0 323.0 Apr 199.0 89.0 104.0 199.0 May 215.0 96.0 50.0 162.0 Jun 228.0 16.0 41.0 154.0 Jul 26.0 49.0 63.0 35.0 Aug 19.0 118.0 55.0 180.0 Sep 94.0 92.0 57.0 161.0 Oct 150.0 47.0 42.0 142.0 Nov 18.0 118.0 160.0 81.0 Dec 128.0 234.0 344.0 76.0" # read into data frame DF <- read.table(textConnection(Lines), header = TRUE, check.names = FALSE) tt <- c(as.matrix(DF)) # create ts object tt.ts st <- as.numeric(names(DF)[2]) # 1903 tt.ts <- ts(tt, freq = 12, start = st) plot(tt.ts) On Wed, May 26, 2010 at 10:30 PM, Zablone Owiti <zowiti@ncst.go.ke> wrote:> Dear users, > > I have several columns of data (each column containing monthly data fora> particular year from january - december) . I would wish to combine the > columns to get a Single column of continuous data as shown in (b) below.I> have read this data as table in R > (a) Data example > > Year 1903 1904 1905 1906 Jan 125.0 30.0 113.05.0 Feb> 128.0 100.0 70.0 388.0 Mar 155.0 79.0 230.0323.0 Apr> 199.0 89.0 104.0 199.0 May 215.0 96.0 50.0 162.0Jun> 228.0 16.0 41.0 154.0 Jul 26.0 49.0 63.0 35.0Aug 19.0> 118.0 55.0 180.0 Sep 94.0 92.0 57.0 161.0Oct 150.0> 47.0 42.0 142.0 Nov 18.0 118.0 160.0 81.0 Dec128.0> 234.0 344.0 76.0 > > (b)Single column : > > Jan 125.0 Feb 128.0 Mar 155.0 Apr 199.0 May215.0 Jun> 228.0 Jul 26.0 Aug 19.0 Sep 94.0 Oct150.0 Nov 18.0> Dec 128.0 Jan 30.0 Feb 100.0 Mar 79.0 Apr89.0 May> 96.0 Jun 16.0 Jul 49.0 Aug 118.0 Sep 92.0Oct 47.0> Nov 118.0 Dec 234.0 Jan 113.0 Feb 70.0 Mar230.0 Apr> 104.0 May 50.0 Jun 41.0 Jul 63.0 Aug55.0 Sep 57.0> Oct 42.0 Nov 160.0 Dec 344.0 > > Jan 5.0 Feb 388.0 Mar 323.0 Apr 199.0 May162.0 Jun> 154.0 Jul 35.0 Aug 180.0 Sep 161.0 Oct 142.0Nov 81.0> Dec 76.0 > > Thanks > > ---------------------------- > ZABLONE OWITI > GRADUATE STUDENT > College of Atmospheric Science > Nanjing University of Information, Science and Technology > Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China > Tel: +86-25-58731402 > Fax: +86-25-58731456 > Mob. 15077895632 > Website: www.nuist.edu.cn > ===================================================> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >______________________________________________ R-help@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. [[alternative HTML version deleted]]
Gabor Grothendieck
2010-May-27 09:41 UTC
[R] How to combine data columns to a single column
On Wed, May 26, 2010 at 10:51 PM, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> This is a time series so its best to represent it as such using a ts > object. ?Below tt is the vector of data you asked for and tt.ts is the > same vector converted into a ts series: > > Lines <- "Year 1903 1904 1905 1906 > Jan 125.0 30.0 113.0 5.0 > Feb 128.0 100.0 70.0 388.0 > Mar 155.0 79.0 230.0 323.0 > Apr 199.0 89.0 104.0 199.0 > May 215.0 96.0 50.0 162.0 > Jun 228.0 16.0 41.0 154.0 > Jul 26.0 49.0 63.0 35.0 > Aug 19.0 118.0 55.0 180.0 > Sep 94.0 92.0 57.0 161.0 > Oct 150.0 47.0 42.0 142.0 > Nov 18.0 118.0 160.0 81.0 > Dec 128.0 234.0 344.0 76.0" > > # read into data frame > DF <- read.table(textConnection(Lines), header = TRUE, check.names = FALSE) > tt <- c(as.matrix(DF))This last line should be: tt <- c(as.matrix(DF[-1])) as was pointed out offline.> > # create ts object tt.ts > st <- as.numeric(names(DF)[2]) # 1903 > tt.ts <- ts(tt, freq = 12, start = st) > > plot(tt.ts) > > On Wed, May 26, 2010 at 10:30 PM, Zablone Owiti <zowiti at ncst.go.ke> wrote: >> Dear users, >> >> I have several columns of data (each column containing monthly data for a >> particular year from january - december) . I would wish ?to combine ?the >> columns to get a Single column of continuous data as shown in (b) below. I >> have read this data as table in R >> (a) Data example >> >> Year ? ? 1903 ? ?1904 ? ?1905 ? ?1906 ? ?Jan ? ? 125.0 ? 30.0 ? ?113.0 ? 5.0 ? ? Feb >> ? ? ? ? 128.0 ? 100.0 ? 70.0 ? ?388.0 ? Mar ? ? 155.0 ? 79.0 ? ?230.0 ? 323.0 ? Apr >> 199.0 ? ?89.0 ? ?104.0 ? 199.0 ? May ? ? 215.0 ? 96.0 ? ?50.0 ? ?162.0 ? Jun >> 228.0 ? ?16.0 ? ?41.0 ? ?154.0 ? Jul ? ? 26.0 ? ?49.0 ? ?63.0 ? ?35.0 ? ?Aug ? ? 19.0 >> ? ? ? ? 118.0 ? 55.0 ? ?180.0 ? Sep ? ? 94.0 ? ?92.0 ? ?57.0 ? ?161.0 ? Oct ? ? 150.0 >> 47.0 ? ? 42.0 ? ?142.0 ? Nov ? ? 18.0 ? ?118.0 ? 160.0 ? 81.0 ? ?Dec ? ? 128.0 >> 234.0 ? ?344.0 ? 76.0 >> >> (b)Single column : >> >> Jan ? ? ?125.0 ? Feb ? ? 128.0 ? Mar ? ? 155.0 ? Apr ? ? 199.0 ? May ? ? 215.0 ? Jun >> ? ? ? ? 228.0 ? Jul ? ? 26.0 ? ?Aug ? ? 19.0 ? ?Sep ? ? 94.0 ? ?Oct ? ? 150.0 ? Nov ? ? 18.0 >> Dec ? ? ?128.0 ? Jan ? ? 30.0 ? ?Feb ? ? 100.0 ? Mar ? ? 79.0 ? ?Apr ? ? 89.0 ? ?May >> 96.0 ? ? Jun ? ? 16.0 ? ?Jul ? ? 49.0 ? ?Aug ? ? 118.0 ? Sep ? ? 92.0 ? ?Oct ? ? 47.0 >> Nov ? ? ?118.0 ? Dec ? ? 234.0 ? Jan ? ? 113.0 ? Feb ? ? 70.0 ? ?Mar ? ? 230.0 ? Apr >> ? ? ? ? 104.0 ? May ? ? 50.0 ? ?Jun ? ? 41.0 ? ?Jul ? ? 63.0 ? ?Aug ? ? 55.0 ? ?Sep ? ? 57.0 >> Oct ? ? ?42.0 ? ?Nov ? ? 160.0 ? Dec ? ? 344.0 >> >> Jan ? ? ?5.0 ? ? Feb ? ? 388.0 ? Mar ? ? 323.0 ? Apr ? ? 199.0 ? May ? ? 162.0 ? Jun >> 154.0 ? ?Jul ? ? 35.0 ? ?Aug ? ? 180.0 ? Sep ? ? 161.0 ? Oct ? ? 142.0 ? Nov ? ? 81.0 >> Dec ? ? ?76.0 >> >> Thanks >> >> ---------------------------- >> ?ZABLONE OWITI >> ?GRADUATE STUDENT >> College of Atmospheric Science >> Nanjing University of Information, Science and Technology >> Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China >> ?Tel: +86-25-58731402 >> Fax: +86-25-58731456 >> Mob. 15077895632 >> Website: ?www.nuist.edu.cn >> ===================================================>> >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> ______________________________________________ >> 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. >> >