Hi there: I am a total beginner in R, and I have a simple question: I have a table with thousands of lines that represent locations, and two columns: latitude and longitude. I need to randomly sample 1000 lines. How do I do it? I know the command "sample", but it samples elements independently, not lines. If there is a better place for me to ask that type of question, please let me know. Thanks a lot, Mariana (from Brazil) -- View this message in context: http://r.789695.n4.nabble.com/Anyone-can-help-with-this-question-tp3045265p3045265.html Sent from the R help mailing list archive at Nabble.com.
Try this: DF[sample(seq(nrow(DF)), 1000),] Where DF is your data On Tue, Nov 16, 2010 at 3:13 PM, Mariana <mvale.eco@gmail.com> wrote:> > Hi there: > I am a total beginner in R, and I have a simple question: > I have a table with thousands of lines that represent locations, and two > columns: latitude and longitude. I need to randomly sample 1000 lines. How > do I do it? I know the command "sample", but it samples elements > independently, not lines. > If there is a better place for me to ask that type of question, please let > me know. > Thanks a lot, > Mariana (from Brazil) > > -- > View this message in context: > http://r.789695.n4.nabble.com/Anyone-can-help-with-this-question-tp3045265p3045265.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
On Nov 16, 2010, at 12:13 PM, Mariana wrote:> > Hi there: > I am a total beginner in R,Time to read the Posting Guide. (Especially since Nabble appears to deficient in providing an introductory document, at least judging from the email behavior of some of its users.)> and I have a simple question: > I have a table with thousands of lines that represent locations, and > two > columns: latitude and longitude. I need to randomly sample 1000 > lines. How > do I do it? I know the command "sample", but it samples elements > independently, not lines.So use that vector as an index: latlong.tbl[ sample(NROW(latlong.tbl), 1000) , ] # should work for matrices or dataframes or table objects> If there is a better place for me to ask that type of question, > please let > me know. > Thanks a lot, > Mariana (from Brazil)-- David Winsemius, MD West Hartford, CT
assuming your data takes the form of location latitude longitude string num num string2 num num try: sub <- dat[sample.int(length(dat$location), 1000),] -------------------------------------- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 "Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it." - Jubal Early, Firefly r-help-bounces at r-project.org wrote on 11/16/2010 12:13:57 PM:> [image removed] > > [R] Anyone can help with this question > > Mariana > > to: > > r-help > > 11/16/2010 02:22 PM > > Sent by: > > r-help-bounces at r-project.org > > > Hi there: > I am a total beginner in R, and I have a simple question: > I have a table with thousands of lines that represent locations, and two > columns: latitude and longitude. I need to randomly sample 1000 lines.How> do I do it? I know the command "sample", but it samples elements > independently, not lines. > If there is a better place for me to ask that type of question, pleaselet> me know. > Thanks a lot, > Mariana (from Brazil) > > -- > View this message in context: http://r.789695.n4.nabble.com/Anyone- > can-help-with-this-question-tp3045265p3045265.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.