Re: [R] Sampling from a Matrix

2006-08-10 Thread Daniel Gerlanc
the description of the > problem, rather than the code provided, presuming that the code was not > correct, including the use of 'replace' and 'prob' in sample(). > > I suppose it would be up to Daniel for clarification. > > Regards, > > Marc > > &

[R] Sampling from a Matrix

2006-08-04 Thread Daniel Gerlanc
3, replace = TRUE, prob = probs[i, ]) } Is there a another way to do this? Thanks! Dan Gerlanc -- Daniel Gerlanc Williams College '07 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the pos

[R] Vectorizing a "for" loop

2006-08-03 Thread Daniel Gerlanc
Hello all, Consider the following problem: There are two vectors: rows <- c(1, 2, 3, 4, 5) columns <- c(10, 11, 12, 13, 14) I want to create a matrix with dimensions length(rows) x length(columns): res <- matrix(nrow = length(rows), ncol = length(columns)) If "i" and "j" are the row and colum

[R] How to split the left and right hand terms of a formula

2006-07-26 Thread Daniel Gerlanc
Hello All, I've sent a few messages to the list regarding splitting a formula into its right and left hand terms. Thanks to everyone who has responded. I believe that the best way to extract the left and right hand terms as character vectors follows: library(nlme) formula <- y ~ x + z left.te

[R] Follow Up To: Splitting the left and right hand terms of a formula

2006-07-25 Thread Daniel Gerlanc
Hi All, I sent the following message to R-help on July 14th, 2006: Let's say I have the following formula: a.formula <- x ~ y + z I want to extract the left and right-hand sides of the function so that I have two character vectors like the ones you would create using the following assignments:

[R] Splitting the left and right hand terms of a formula

2006-07-14 Thread Daniel Gerlanc
"y", "z") One way to do this follows: left.hand.side <- unlist(dimnames(attr(terms(a.formula), "factors"))[1]) right.hand.side <- unlist(dimnames(attr(terms(a.formula), "factors"))[-1]) Is there a better or