[R] creating a loop if to create a column of 0 and 1.

PIKAL Petr petr.pikal at precheza.cz
Wed Apr 3 09:45:17 CEST 2013


Hi

Check your keyboard, your enter key must be broken. If I decrypt your message and assume that Nfiltered and Presyabs has the same length, then

Presyabs[Nfiltered==0] <- 0

In case you have some missing values use 

Presyabs[which(Nfiltered==0)] <- 0

Without knowledge of structure of CPOD objects it is difficult to elaborate it further.

> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

Regards
Petr


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Marco A. Pérez
> Sent: Wednesday, April 03, 2013 1:00 AM
> To: r-help at r-project.org
> Subject: [R] creating a loop if to create a column of 0 and 1.
> 
> 
> Hi, I am new with rstudio and i have a trouble with this program. I
> store 17 listsCPOD<-list()CPOD[[1]]<- GB1ACPOD[[2]]<- GB1CCPOD[[3]]<-
> GB1DCPOD[[4]]<- GB2ACPOD[[5]]<- GB2BCPOD[[6]]<- GB2CCPOD[[7]]<-
> GB2DCPOD[[8]]<- GB3ACPOD[[9]]<- GB3CCPOD[[10]]<- GB3DCPOD[[11]]<-
> GB4ACPOD[[12]]<- GB4CCPOD[[13]]<- GB4DCPOD[[14]]<- GB5ACPOD[[15]]<-
> GB5BCPOD[[16]]<- GB5CCPOD[[17]]<- GB5D Each each file you can find a
> txt document that contains the columns: file, chuckend, Nfiltered,
> Nall, MinsOn and Presyabs. What I want to do is to create a loop for
> all the CPODs. If the row of the column Nfiltered is 0 then the row of
> the column Presyabs must be 0 if it is different than 0 then it must be
> 1.
> I create this loop without success#Creating the loop (0-1 presence,
> absence)
> for(i in 1:length(CPOD[[1]]$Presyabs)){  if (CPOD[[1]]$Nfiltered[i]<1)
> (CPOD[[1]]$Presyabs[i]=1)}  else {    (CPOD[[1] ]$Presyabs[[i]]=0)}  }
> Thank you for your prompt answer
> 	[[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.



More information about the R-help mailing list