[R] Random number
Sundar Dorai-Raj
sundar.dorai-raj at PDF.COM
Wed Oct 27 19:57:17 CEST 2004
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
More information about the R-help
mailing list