[R] Vector manipulation, for loop needed?
clips10
m.mcquillan at lancaster.ac.uk
Fri Jun 18 16:52:54 CEST 2010
Hi,
I have a vector of time in days t<-1:48.
I have observations and the day they were recorded. I also have a vector, S
which takes different values depending on which day the observation was
recorded. For example if on day 1 all in vector S get a value of 46/48, on
day 2 get 42/48, day 3 38/48, decreasing by 4/48 each time until day 12 gets
the value 2/48. Then for any day greater than 12 the vector S has value 0.
I want to create a vector which gives the values of S in terms of days, t.
I have tried:
t<-1:48
for(i in 1:t){
S<-rep(0,48)
if(t<12){
S[i]<-(48-3*t)/48}
else{
S[i]<-0}
}
but this doesn't work. I'm fairly new to R and don't have much skill in
manipulating things. I'm trying to plot time against this vector so need it
in terms of t. Sorry that this isn't even very clear in what I want and I'm
aware that the (48-3*t)/48 won't even give me the
46/48,42/48,38/48....2/48,0....0 pattern I'm after but no idea what to do!
Any help would be great.
Thanks
--
View this message in context: http://r.789695.n4.nabble.com/Vector-manipulation-for-loop-needed-tp2260334p2260334.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list