Re: [R] Extracting random rows from a dataset

2012-11-22 Thread Madhu Ganganapalli
I found this code through internet and I have a one doubt about this example, which is Here you take a 70% random sample considering all the values but what I want is if the selected sample contains p1,p2 then I want all records of p1,p2 and also remaining data in some other data frame...like fo

Re: [R] Extracting random rows from a dataset

2009-01-18 Thread S.Putoto
Thank you everybody, problem solved! :) David Winsemius wrote: > > > > read.table(textConnection(gsub("\\(|\\)", "", var) )) #from prior > posting >V1 V2 > 1 p1 10 > 2 p1 3 > 3 p1 4 > 4 p2 20 > 5 p2 30 > 6 p2 40 > 7 p3 4 > 8 p3 1 > 9 p1 2 > > > ridxs <- sample(1:nrow(df),floor(0.

Re: [R] Extracting random rows from a dataset

2009-01-18 Thread David Winsemius
> read.table(textConnection(gsub("\\(|\\)", "", var) )) #from prior posting V1 V2 1 p1 10 2 p1 3 3 p1 4 4 p2 20 5 p2 30 6 p2 40 7 p3 4 8 p3 1 9 p1 2 > ridxs <- sample(1:nrow(df),floor(0.7*nrow(df)) ) # the 70% sample row IDs > df[ridxs,] V1 V2 5 p2 30 6 p2 40 2 p1 3 7 p3 4 4

Re: [R] Extracting random rows from a dataset

2009-01-18 Thread jim holtman
Here is one way to do it: > x <- matrix(1:100,10) > x [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]1 11 21 31 41 51 61 71 8191 [2,]2 12 22 32 42 52 62 72 8292 [3,]3 13 23 33 43 53 63 73 8393 [4,]4 14

[R] Extracting random rows from a dataset

2009-01-18 Thread S.Putoto
Hello dear R Users, I am working on a dataset of 928 Enterprises, of which are observed 12 different characters. I need to randomly sample, without repetition, 70% of the entreprises, to create a testing set, and let the other 30% of the enterprises be a validating set (holdout validation, I thin