[R] vector and replace.
Erin Hodgess
hodgess at gator.uhd.edu
Sat Mar 13 04:32:17 CET 2004
Hi Yong!
How about this:
> gsr <- sample(c("g","r","y"),replace=T,15)
> gsr
[1] "r" "g" "r" "g" "y" "y" "r" "r" "y" "g" "r" "y" "r" "r" "g"
> as.numeric(as.factor(gsr))
[1] 2 1 2 1 3 3 2 2 3 1 2 3 2 2 1
>
Hope this helps!
Sincerely,
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: hodgess at gator.uhd.edu
Date: Fri, 12 Mar 2004 19:37:18 -0600 (CST)
From: Yong Wang <wang at galton.uchicago.edu>
To: r-help-request at stat.math.ethz.ch
cc: r-help at stat.math.ethz.ch
hi,all
a quick question:
a vector
v<-c(g,r,y,g,y,y,r)
needs to be
v<-c(1,2,3,1,3,3,2)
i.e., replace g,r,y as 1,2,3
how to do that, by the way, what key words I should use to search for such
basic operation command?
thank you
best
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.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