[R] HELP!! how to remove 10% of data randomly in R

arun smartpink111 at yahoo.com
Tue Oct 30 18:42:28 CET 2012


Hi,
Try this:
dat1<-read.table(text="
  V1 V2
1 5 10
2 6  3
3 8  4
4 9 20
5 15 30
6 25 40
7 2  4
8 3  1
9 1  5
10 8 10
",header=TRUE)
dat1[sample(1:nrow(dat1), 0.50*nrow(dat1)),] #50% of data
#   V1 V2
#4   9 20
#6  25 40
#8   3  1
#10  8 10
#9   1  5
dat1[-sample(1:nrow(dat1), 0.90*nrow(dat1)),] #remove 90% of data
#  V1 V2
#7  2  4




----- Original Message -----
From: Eugenie <leemeanwei at hotmail.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, October 30, 2012 11:12 AM
Subject: [R] HELP!! how to remove 10% of data randomly in R

any can please tell me how to remove 10%,15%,25% and 50% of the data randomly
by using R programme???
can anyone please show me the coding?
do i need to install any package?



--
View this message in context: http://r.789695.n4.nabble.com/HELP-how-to-remove-10-of-data-randomly-in-R-tp4647879.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list