[R] Randomly split a sample in two equal subsamples

yoan yoan.mihov at gmail.com
Sun Oct 31 18:52:37 CET 2010


Thanks, but I just don't know how to translate that to a dataset with
rows and columns.
Initially, I was thinking about something like that:

# Create some data:
a <- c(10,20,15,43,76,41,25,46)
b <- factor(c("m", "w", "m", "w", "m", "w", "m", "w"))
c <- c(2,5,8,3,6,1,5,6)
number <- c(1:8)
myframe <- data.frame(a,b,c, number)

# Randomly sample a subset of "numbers":
v1 <- sample(number, 4, replace=FALSE)
v2 <- number[-v1]

# Use the "subset" command like this:
firsthalf <- subset(myframe, number=v1)

Of course, the last line doesn't work. Is this generally a wrong
approach, or is just my writing wrong?
-- 
View this message in context: http://r.789695.n4.nabble.com/Randomly-split-a-sample-in-two-equal-subsamples-tp3021140p3021339.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list