It is not exactly clear from your message what you want. If you want n random values holding either -1, 0 or 1, use sample(c(-1,0,1), 10, replace=TRUE) or also sample(3, 10, replace=TRUE)-2 If you want n values following the pattern -1, 0, 1, 0 as your example seems to follow, use n<-10 pattern<- c(-1,0,1,0) rep(pattern, ceiling(n/length(pattern)))[1:n]
If you want a sequence of random real numbers between -1 and 1, use runif(10, min=-1, max=1) Here's hoping I haven't just solved your homework... Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Rustamali Manesiya Sent: donderdag 13 januari 2011 5:12 To: r-help@r-project.org Subject: [R] Repeating value occurence How can achieve this in R using seq, or rep function c(-1,0,1,0,-1,0,1,0,-1,0) The range value is between-1 and 1, and I want it such that there could be n number of points between -1 and 1 Anyone? Please help Thanks Rusty [[alternative HTML version deleted]] ______________________________________________ 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. ______________________________________________ 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.