Xiao Shi
2005-Oct-09 09:26 UTC
[R] How to get the remaining vector after sampling a subset?
Hi , I have a vector,for example, x=rnorm(100) Then i rendom choose 20 of them. chosen=sample(x,20). And i want to get the remain values in x. Is there a quick way to go? Thanks in advance. [[alternative HTML version deleted]]
Sundar Dorai-Raj
2005-Oct-09 09:41 UTC
[R] How to get the remaining vector after sampling a subset?
Xiao Shi wrote:> Hi , > I have a vector,for example, > x=rnorm(100) > Then i rendom choose 20 of them. > chosen=sample(x,20). > And i want to get the remain values in x. > Is there a quick way to go? > > Thanks in advance. > > [[alternative HTML version deleted]] >How about: x <- rnorm(100) y <- sample(x, 20) z <- x[!x %in% y] But probably a safer way is to sample the indicies: x <- rnorm(100) w <- sample(length(x), 20) y <- x[w] z <- x[-w] HTH, --sundar
Dimitris Rizopoulos
2005-Oct-09 09:45 UTC
[R] How to get the remaining vector after sampling a subset?
one way is to use: x[!x %in% chosen] I hope it helps. Best, Dimitris ----- Original Message ----- From: "Xiao Shi" <bioconductor.cn at gmail.com> To: <r-help at stat.math.ethz.ch> Sent: Sunday, October 09, 2005 11:26 AM Subject: [R] How to get the remaining vector after sampling a subset?> Hi , > I have a vector,for example, > x=rnorm(100) > Then i rendom choose 20 of them. > chosen=sample(x,20). > And i want to get the remain values in x. > Is there a quick way to go? > > Thanks in advance. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Reasonably Related Threads
- how to get such a subset of a matrix?
- How to plot a matrix with 18 rows by row vs. a vector in a single graph, resulting 18 lines with different colors?
- how to generate object name automatically?
- intersect more than two sets
- Converting indices of a matrix subset