# [R] Repeating value occurence

Nick Sabbe nick.sabbe at ugent.be
Thu Jan 13 09:16:19 CET 2011

```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.sabbe at ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36

-- Do Not Disapprove

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Rustamali Manesiya
Sent: donderdag 13 januari 2011 5:12
To: r-help at 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

Rusty

[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help