Dear r-users, I have daily rainfall data from 1971 to 2000. I would like to extract november and december data only. I would also like to do column bind for november and december, therefore I would like to delete 31 December from december data so that the length of november and december are the same. Hope somebody can help me. I tried this below:> kuantan.dt.1 <- kuantan.dt[(kuantan.dt$Bulan >=11) & (kuantan.dt$Bulan <= 12),] > head(kuantan.dt.1) ; tail(kuantan.dt.1)Tahun Bulan Hari Jumlah.Hujan.mm. 305 71 11 1 0.0 306 71 11 2 16.3 307 71 11 3 0.0 308 71 11 4 0.0 309 71 11 5 12.2 310 71 11 6 4.6 Tahun Bulan Hari Jumlah.Hujan.mm. 10953 0 12 26 0.0 10954 0 12 27 0.0 10955 0 12 28 20.0 10956 0 12 29 15.5 10957 0 12 30 6.4 10958 0 12 31 9.3 [[alternative HTML version deleted]]
Something like this...untested I think cbind recicles the last value(31) since nov and dec are of different length nov <- kuantan.dt[(kuantan.dt$Bulan >=11);nov dec <- kuantan.dt[(kuantan.dt$Bulan >=12);dec both <- cbind(nov,dec) # get the first 30 records both <- head(both,30);both Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx From: Roslina Zakaria <zroslina@yahoo.com>>To: "r-help@r-project.org" <r-help@r-project.org> >Sent: Sunday, November 11, 2012 6:39 PM >Subject: [R] arrange data > >Dear r-users, > >I have daily rainfall data from 1971 to 2000. I would like to extract november and december data only. I would also like to do column bind for november and december, therefore I would like to delete 31 December from december data so that the length of november and december are the same. Hope somebody can help me. I tried this below: > >> kuantan.dt.1 <- kuantan.dt[(kuantan.dt$Bulan >=11) & (kuantan.dt$Bulan <= 12),] >> head(kuantan.dt.1) ; tail(kuantan.dt.1) > Tahun Bulan Hari Jumlah.Hujan.mm. >305 71 11 1 0.0 >306 71 11 2 16.3 >307 71 11 3 0.0 >308 71 11 4 0.0 >309 71 11 5 12.2 >310 71 11 6 4.6 > Tahun Bulan Hari Jumlah.Hujan.mm. >10953 0 12 26 0.0 >10954 0 12 27 0.0 >10955 0 12 28 20.0 >10956 0 12 29 15.5 >10957 0 12 30 6.4 >10958 0 12 31 9.3 > [[alternative HTML version deleted]] > > >______________________________________________ >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]]
HI, I think it would be better to store this as a list. For example: list1<- list(kuantan.dt[kuantan.dt[,2]==11,],kuantan.dt[kuantan.dt[,2]==12,]) If you wanted to delete 31 December and do column bind: res<-cbind(kuantan.dt[kuantan.dt[,2]==11,], kuantan.dt[kuantan.dt[,2]==12 & kuantan.dt[,3]!=31,]) # assuming 3rd column corresponds to day A.K. ----- Original Message ----- From: Roslina Zakaria <zroslina at yahoo.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Sunday, November 11, 2012 9:39 PM Subject: [R] arrange data Dear r-users, ? I have daily rainfall data from 1971 to 2000.? I would like to extract november and december data only.? I would also like to do column bind for november and december, therefore I would like to delete 31 December from december data so that the length of november and december are the same.? Hope somebody can help me.? I tried this below: ?> kuantan.dt.1 <- kuantan.dt[(kuantan.dt$Bulan >=11) & (kuantan.dt$Bulan <= 12),] > head(kuantan.dt.1) ; tail(kuantan.dt.1)??? Tahun Bulan Hari Jumlah.Hujan.mm. 305??? 71??? 11??? 1????????????? 0.0 306??? 71??? 11??? 2???????????? 16.3 307??? 71??? 11??? 3????????????? 0.0 308??? 71??? 11??? 4????????????? 0.0 309??? 71??? 11??? 5???????????? 12.2 310??? 71??? 11??? 6????????????? 4.6 ????? Tahun Bulan Hari Jumlah.Hujan.mm. 10953???? 0??? 12?? 26????????????? 0.0 10954???? 0??? 12?? 27????????????? 0.0 10955???? 0??? 12?? 28???????????? 20.0 10956???? 0??? 12?? 29???????????? 15.5 10957???? 0??? 12?? 30????????????? 6.4 10958???? 0??? 12?? 31????????????? 9.3 ??? [[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.
Since you specifically want either nov or dec you actually don't need '>=' use instead '= =' Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx From: Roslina Zakaria <zroslina@yahoo.com>>To: Felipe Carrillo <mazatlanmexico@yahoo.com> >Sent: Sunday, November 11, 2012 10:56 PM >Subject: Re: [R] arrange data > > >Thank you so much Felipe, I'll try your suggestion. > > >From: Felipe Carrillo <mazatlanmexico@yahoo.com> >To: Roslina Zakaria <zroslina@yahoo.com>; "r-help@r-project.org" <r-help@r-project.org> >Sent: Monday, November 12, 2012 12:09 PM >Subject: Re: [R] arrange data > > >Something like this...untested >I think cbind recycles the last value(31) since nov and dec are of different length >nov <- kuantan.dt[(kuantan.dt$Bulan >=11);nov >dec <- kuantan.dt[(kuantan.dt$Bulan >=12);dec >both <- cbind(nov,dec) ># get the first 30 records >both <- head(both,30);both > > > >Felipe D. Carrillo >Supervisory Fishery Biologist >Department of the Interior >US Fish & Wildlife Service >California, USA >http://www.fws.gov/redbluff/rbdd_jsmp.aspx > > > >From: Roslina Zakaria <zroslina@yahoo.com> >>To: "r-help@r-project.org" <r-help@r-project.org> >>Sent: Sunday, November 11, 2012 6:39 PM >>Subject: [R] arrange data >> >>Dear r-users, >> >>I have daily rainfall data from 1971 to 2000. I would like to extract november and december data only. I would also like to do column bind for november and december, therefore I would like to delete 31 December from december data so that the length of november and december are the same. Hope somebody can help me. I tried this below: >> >>> kuantan.dt.1 <- kuantan.dt[(kuantan.dt$Bulan >=11) & (kuantan.dt$Bulan <= 12),] >>> head(kuantan.dt.1) ; tail(kuantan.dt.1) >> Tahun Bulan Hari Jumlah.Hujan.mm. >>305 71 11 1 0.0 >>306 71 11 2 16.3 >>307 71 11 3 0.0 >>308 71 11 4 0.0 >>309 71 11 5 12.2 >>310 71 11 6 4.6 >> Tahun Bulan Hari Jumlah.Hujan.mm. >>10953 0 12 26 0.0 >>10954 0 12 27 0.0 >>10955 0 12 28 20.0 >>10956 0 12 29 15.5 >>10957 0 12 30 6.4 >>10958 0 12 31 9.3 >> [[alternative HTML version deleted]] >> >> >>______________________________________________ >>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]]