Re: [R] Vector manipulation, for loop needed?

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Fri, 18 Jun 2010 16:54:45 -0400

?ifelse

HTH,
Jorge

On Fri, Jun 18, 2010 at 10:52 AM, clips10 <> wrote:

>
> 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.
>
> ______________________________________________
> R-help_at_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.
>

        [[alternative HTML version deleted]]



R-help_at_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. Received on Fri 18 Jun 2010 - 21:01:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 18 Jun 2010 - 21:10:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive