try this > a<-c(1, 6, 8, 9) > 1*(1:10 %in% a) [1] 1 0 0 0 0 1 0 1 1 0
Stefano -----Messaggio originale----- Da: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]per conto di njhuang86 Inviato: Friday, June 12, 2009 4:45 PM A: r-help@r-project.org Oggetto: [R] Creating this vector, any suggetions? 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! -- View this message in context: http://www.nabble.com/Creating-this-vector%2C-any-suggetions--tp24000348p24000348.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Rispetta l'ambiente: Se non ti è necessario, non stampare questa mail. "Le informazioni contenute nel presente messaggio di posta elettronica e in ogni suo allegato sono da considerarsi riservate e il destinatario della email è l'unico autorizzato ad usarle, copiarle e, sotto la propria responsabilità, divulgarle. Chiunque riceva questo messaggio per errore senza esserne il destinatario deve immediatamente rinviarlo al mittente cancellando l'originale. Eventuali dati personali e sensibili contenuti nel presente messaggio e/o suoi allegati vanno trattati nel rispetto della normativa in materia di privacy ( DLGS n.196/'03)". ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.