[R] loop problem

crenial30 cool_unmesh at yahoo.co.in
Fri Oct 2 13:34:27 CEST 2009


Thanks a lot David for your answer. I am sorry for being so minimal.

I wanted to produce a list/vector/table consisting each vector produced from
this code

len<-20
for (n1 in seq(0,(len-1),by=1)){

f <- R_event[R_event > (rx[1]+ n1*300)& R_event <= (rx[1] + 300*(n1+1))]
//create list for each values of n1

R_ev_char <- as.character(f)

lis01 <- c(length(R_ev_char)) // here I want to store the values of lengths
of R_ev_char vector for successive values of n1(0,1,2,3,...20)

I already tried with vector notation but no help.

I just want to store Lengths on each successive  integer so that I can draw
the list on 300(secs) interval.

Any suggestion would be very much helpful.
crenial


crenial30 wrote:
> 
> I have the following code which I wanted to convert using for loop
> 
> previous code:
> R_ev1 <- R_event[R_event > (rx[1] + 300*0)& R_event <= (rx[1] + 300*1)]
> R_ev2 <- R_event[R_event > (rx[1] + 300*1)& R_event <= (rx[1] + 300*2)]
> R_ev3 <- R_event[R_event > (rx[1] + 300*2)& R_event <= (rx[1] + 300*3)]
> R_ev4 <- R_event[R_event > (rx[1] + 300*3)& R_event <= (rx[1] + 300*4)]
> 
> R_ev5 <- R_event[R_event > (rx[1] + 300*4)& R_event <= (rx[1] + 300*5)]
> R_ev6 <- R_event[R_event > (rx[1] + 300*5)& R_event <= (rx[1] + 300*6)]
> R_ev7 <- R_event[R_event > (rx[1] + 300*6)& R_event <= (rx[1] + 300*7)]
> R_ev8 <- R_event[R_event > (rx[1] + 300*7)& R_event <= (rx[1] + 300*8)]
> 
> R_ev9 <- R_event[R_event  > (rx[1] + 300*8)& R_event <= (rx[1] + 300*9)]
> R_ev10 <- R_event[R_event > (rx[1] + 300*9)& R_event <= (rx[1] + 300*10)]
> R_ev11 <- R_event[R_event > (rx[1] + 300*10)& R_event <= (rx[1] + 300*11)]
> R_ev12 <- R_event[R_event > (rx[1] + 300*11)& R_event <= (rx[1] + 300*12)]
> 
> R_ev13 <- R_event[R_event > (rx[1] + 300*12)& R_event <= (rx[1] + 300*13)]
> R_ev14 <- R_event[R_event > (rx[1] + 300*13)& R_event <= (rx[1] + 300*14)]
> R_ev15 <- R_event[R_event > (rx[1] + 300*14)& R_event <= (rx[1] + 300*15)]
> R_ev16 <- R_event[R_event > (rx[1] + 300*15)& R_event <= (rx[1] + 300*16)]
> 
> 
> R_ev1c <- as.character(R_ev1)
> R_ev2c <- as.character(R_ev2)
> R_ev3c <- as.character(R_ev3)
> R_ev4c <- as.character(R_ev4)
> R_ev5c <- as.character(R_ev5)
> R_ev6c <- as.character(R_ev6)
> R_ev7c <- as.character(R_ev7)
> R_ev8c <- as.character(R_ev8)
> 
> R_ev9c  <- as.character(R_ev9)
> R_ev10c <- as.character(R_ev10)
> R_ev11c <- as.character(R_ev11)
> R_ev12c <- as.character(R_ev12)
> R_ev13c <- as.character(R_ev13)
> R_ev14c <- as.character(R_ev14)
> R_ev15c <- as.character(R_ev15)
> R_ev16c <- as.character(R_ev16)
> 
> 
> 
> 
> lis1 <- c(
> length(R_ev1c),
> length(R_ev2c),
> length(R_ev3c),
> length(R_ev4c),
> length(R_ev5c),
> length(R_ev6c),
> length(R_ev7c),
> length(R_ev8c),
> length(R_ev9c),
> length(R_ev10c),
> length(R_ev11c),
> length(R_ev12c),
> length(R_ev13c),
> length(R_ev14c),
> length(R_ev15c),
> length(R_ev16c)
> )
> 
> 
> # R_ev1_mat <- matrix(unlist(R_ev1),nrow=T)
> 
> 
> barplot(lis1, angle = 15+10*1:5, density = 20, col = "black",
>        legend = rownames(lis1))
>  title(main = list("Number of Occurred Received events in every 5 mins",
> font = 4))
> 
> # dev.off()
> 
> 
> New code:
> 
> f1<- seq(rx[1],rx[2],by=300)
> f<- as.character(f1)
> len <- length(f)
> 
> for (n1 in 0:(len-1)){
> for(n2 in 1:len){
> # R_ev_01 <- R_event[R_event <= (rx[1] + 300)]
> 
> R_ev[n1] <- R_event[R_event > (rx[1]+ n1*300)& R_event <= (rx[1] +
> 300*n2)]
> R_ev_char <- as.character(R_ev)
> 
> lis01 <- list(length(R_ev_char))
> barplot(lis01, angle = 15+10*1:5, density = 20, col = "blue",
>        legend = rownames(lis01))
>  title(main = list("Number of Occurred Received Events in every 5 mins",
> font = 4))
> }
> }
> 
> Somehow it is not working and giving an error saying "Fehler in -0.01 *
> height : nicht-numerisches Argument für binären Operator".
> 
> Any help would be really appreciated.
> 
> Thanks
> Crenial
> 

-- 
View this message in context: http://www.nabble.com/loop-problem-tp25665329p25714305.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list