[R] Value between which elements of a vector?

2011-04-05 Thread beatleb
Dear R-useRs, I am looking for a why to perform the following: specialweeks<-c(0,2,5,12,18,19,20) weeks<-c(1:30) Now I would like that for every week it is even between which elements of vector special weeks it is. For weeks after 20, the value NA or 20, or even 20-30is fine. Thus for week 1:

[R] Fill vector more efficient than element by element?

2011-03-15 Thread beatleb
Dear R useRs, I am a newbie. Currently, my script is quick long, therefor I am trying to improve the efficiency of my script. I use often a version of the following code, the script below is just a simple example, but I especially try to improve the last three lines: matrix1<-diag(100) a=2 try<

[R] sum of variables in function

2011-03-10 Thread beatleb
Dear R users, Probably, this is quite a simpe question, but I do not find the proper way to obtain want I need. To explain the problem, I constructed a simple example. Suppose I have the following function: try1<-function(x){ y<-x[1:2] z<-x[3:4] y[1]*(z[1]+z[2])+y[2]*(z[1]+z[2]) } This functio