CodeGuy
CodeGuy

Reputation: 28907

Splitting a vector into two

How can I split a vector into two such that it selects a random sample for each new vector. But I always want to split in half. For instance

x <- 1:10
obj <- splitMyVector(x)

obj$a
 > 5 3 9 7 10
obj$b
 > 8 4 1 6 2

Note: the purpose for this is to do a split half reliability.

Upvotes: 1

Views: 832

Answers (1)

James
James

Reputation: 66834

split(sample(x),letters[seq(length(x))%%2+1])
$a
[1]  9  7 10  4  2

$b
[1] 6 1 8 3 5

Upvotes: 4

Related Questions