[R] Randomly extract rows from a data frame

2007-02-18 Thread Amy Whitehead
Hi, I am looking for a way to randomly extract a specified number of rows from a data frame. I was planning on binding a column of random numbers to the data frame and then sorting the data frame using this bound column. But I can't figure out how to use this column to sort the entire data

Re: [R] Randomly extract rows from a data frame

2007-02-18 Thread Marc Schwartz
On Mon, 2007-02-19 at 16:10 +1300, Amy Whitehead wrote: Hi, I am looking for a way to randomly extract a specified number of rows from a data frame. I was planning on binding a column of random numbers to the data frame and then sorting the data frame using this bound column. But I can't

Re: [R] Randomly extract rows from a data frame

2007-02-18 Thread David Scott
On Mon, 19 Feb 2007, Amy Whitehead wrote: Hi, I am looking for a way to randomly extract a specified number of rows from a data frame. I was planning on binding a column of random numbers to the data frame and then sorting the data frame using this bound column. But I can't figure out how

Re: [R] Randomly extract rows from a data frame

2007-02-18 Thread Wensui Liu
amy, here is a piece of code copied from my blog, which might answer part of your question. library(MASS); data(Boston); # DIVIDE DATA INTO TESTING AND TRAINING SETS set.seed(2005); test.rows - sample(1:nrow(Boston), 100); test.set - Boston[test.rows, ]; train.set - Boston[-test.rows, ]; On