[R] Creating this vector, any suggetions?

Ben Bolker bolker at ufl.edu
Fri Jun 12 16:50:42 CEST 2009




njhuang86 wrote:
> 
> Suppose I have the first vector: c(1, 6, 8, 9)
> 
> I will like to create a second vector of size 10 composed of 0 and 1's.
> The second vector will be composed of four 1's and six 0's. The position
> of the 1's will be specificed by the first vector. So essentially, I want
> a second vector in the form:
> 
> c(1, 0, 0, 0, 0, 1, 0, 1, 1, 0)
> 
> Any help is greatly appreciated!
> 

z <- numeric(10)
pos <- c(1,6,8,9)
z[pos] <- 1


-- 
View this message in context: http://www.nabble.com/Creating-this-vector%2C-any-suggetions--tp24000348p24000457.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list