What about
x <- c(2,4,7) out<-rep(0,max(x)) out[x]<-1 Regards Wayne -----Original Message----- From: Stefan B�hringer [mailto:[EMAIL PROTECTED] Sent: 26 July 2004 09:46 To: R Help Subject: [R] computing sum of indicator variables My problem is as follows: i is a list of integers of variable length. Now I want to compute a new vector/array that contains 1's at the positions indicated in i. For example: c(2, 4) -> c(0, 1, 0, 1) Using something like i = i - c(0, i[2:length(i) - 1]); sapply(i, function(x) c(rep(0, x - 1), 1))); faces me with the problem of concatenating the result, which I could somehow not find a solution for. Thank you very much in advance. Stefan ______________________________________________ [EMAIL PROTECTED] 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 KSS Ltd Seventh Floor St James's Buildings 79 Oxford Street Manchester M1 6SS England Company Registration Number 2800886 Tel: +44 (0) 161 228 0040 Fax: +44 (0) 161 236 6305 mailto:[EMAIL PROTECTED] http://www.kssg.com The information in this Internet email is confidential and m...{{dropped}} ______________________________________________ [EMAIL PROTECTED] 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
