Dear R- User I created two random number sets using rnorm function and calcuted their respective means. However now I would like to randomly replace some values with NA. Thus create my own test data. Any help or suggestions on this ? Also wanted to confirm when multiplying two random number vectors x am y by matrix..is this how i do it. A is the matrix z <- c(x,y) # x and y the two set of vectors w <- A%*%Z # each element in each vector multipled by the matrix . regards Kunal
Let's say x is of size 100. x <- rnorm(100) x[sample(1:100,10)] <- NA Kunal Shetty <kshe4 at student.monash.edu> Sent by: r-help-bounces at stat.math.ethz.ch 10/27/2004 12:59 PM To: r-help at stat.math.ethz.ch cc: Subject: [R] Random number Dear R- User I created two random number sets using rnorm function and calcuted their respective means. However now I would like to randomly replace some values with NA. Thus create my own test data. Any help or suggestions on this ? Also wanted to confirm when multiplying two random number vectors x am y by matrix..is this how i do it. A is the matrix z <- c(x,y) # x and y the two set of vectors w <- A%*%Z # each element in each vector multipled by the matrix . regards Kunal ______________________________________________ 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
Kunal Shetty wrote:> Dear R- User > > I created two random number sets using rnorm function and calcuted their respective means. However now I would like to randomly > replace some values with NA. Thus create my own test data. > Any help or suggestions on this ? > >Use ?sample: n <- 100 x <- rnorm(n) x[sample(n, 4)] <- NA sum(is.na(x)) # [1] 4> Also wanted to confirm when multiplying two random number vectors x am y by matrix..is this how i do it. > A is the matrix > > z <- c(x,y) # x and y the two set of vectors > > w <- A%*%Z # each element in each vector multipled by the matrix . >(Be careful: R is case sensitive (z != Z).) I'm not really clear what you want here. "%*%" is matrix multiplication and "*" is elementwise multiplication. Also using "c" makes a vector or length "n = length(x) + length(y)". This implies that "A" above "p x n" (i.e. p rows, n columns) and the result "w" would be "p x 1". Please provide an example of what you expect to see by the multiplication. --sundar> > regards > Kunal > > ______________________________________________ > 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