Hi, I have a dataframe in R and would like to split the data (1900-1980) into two sets. For example, one dataframe should have data from 1900-1960 and the other from 1961-1980. Thanks for your help. AT. [[alternative HTML version deleted]]
On Mon, 10 Feb 2014, Zilefac Elvis wrote:> I have a dataframe in R and would like to split the data (1900-1980) into > two sets. For example, one dataframe should have data from 1900-1960 and > the other from 1961-1980.If you want two separate dataframes (while leaving the original), subset() based on the year. For example, one dataframe would select year < 1961 and the other new dataframe would select year > 1960. Rich -- Richard B. Shepard, Ph.D. | Have knowledge, will travel. Applied Ecosystem Services, Inc. | <http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
Suggestions: Read the posting guide mentioned at the bottom of this email. Note request to post in plain text and provide reproducible example. Knowing how your data are constructed allows us to make more concrete suggestions as to how Rio solve your problem. Read help files: ?"%in%", ?subset, ?"<", ?"&". These may seem dense at first, but you eventually need to absorb them so get started. Read the "Introduction to R" document that is supplied with the R software. In particular, read about indexing with logical vectors. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On February 10, 2014 8:58:11 AM PST, Zilefac Elvis <zilefacelvis at yahoo.com> wrote:>Hi, >I have a dataframe in R and would like to split the data (1900-1980) >into two sets. >For example, one dataframe should have data from 1900-1960 and the >other from 1961-1980. >Thanks for your help. >AT. > [[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.
first <- subset(dat1, dat1$var <=1960) Reverse inequality for the other one. Hints on how to ask questions on R-help https://github.com/hadley/devtools/wiki/Reproducibility http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example John Kane Kingston ON Canada> -----Original Message----- > From: zilefacelvis at yahoo.com > Sent: Mon, 10 Feb 2014 08:58:11 -0800 (PST) > To: r-help at r-project.org, r-help-request at r-project.org > Subject: [R] Split dataframe by year > > Hi, > I have a dataframe in R and would like to split the data (1900-1980) into > two sets. > For example, one dataframe should have data from 1900-1960 and the other > from 1961-1980. > Thanks for your help. > AT. > [[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.____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more!