Thanks, it works!
--
View this message in context:
http://r.789695.n4.nabble.com/Randomly-split-a-sample-in-two-equal-subsamples-tp3021140p3021365.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https
firsthalf <- myframe[v1,]
or
firsthalf <- subset(myframe, number %in% v1)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Randomly-split-a-sample-in-two-equal-subsamples-tp3021140p3021353.html
Sent from the R help mailing list archive at Nabble.com.
__
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
Hi Yoan,
Please try ?sample.
Suppose you have 1:n ids of total observations where n is even, you want to
randomly split it into two subsamples, the following code should work.
n <- 20
one.sample <- sort(sample(1:n, n/2))
another.sample <- (1:n)[-one.sample]
Good luck.
Wu
-
A R learner.
Dear all,
I would like to randomly split a sample in two equally large
subsamples. The sample data is stored as a matrix with each row
representing an individual and each column representing some variable
(e.g., name, age, sex, etc.); the first row contains the names of the
variables; the first co
5 matches
Mail list logo