Re: [R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Uli Kleinwechter
That's it, thanks a lot to all of you! Uli Henrique Dallazuanna schrieb: > In grep use: grep("x$", names(data)). > > '$' matchs 'x' in the end of string > > On Fri, Jan 15, 2010 at 11:14 AM, Uli Kleinwechter > wrote: > >> Jim Lemon schrieb: >> >>> On 01/15/2010 07:10 PM, Uli Kleinwechte

Re: [R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Olivier CROUZET
Uli Kleinwechter a écrit : data[,grep("x",names(data))][is.na(data[,grep("x",names(data))])]<-0 thanks a lot. I'm just afraid that grep matches any occurence of "x" in the variable name. So variables which would contain "x" at any position, not necessarily only at the last one would be sel

Re: [R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Henrique Dallazuanna
In grep use: grep("x$", names(data)). '$' matchs 'x' in the end of string On Fri, Jan 15, 2010 at 11:14 AM, Uli Kleinwechter wrote: > Jim Lemon schrieb: >> On 01/15/2010 07:10 PM, Uli Kleinwechter wrote: >>> Dear all, >>> >>> I'm looking for a way to replace NA's with 0 for a number of variables

Re: [R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Uli Kleinwechter
Jim Lemon schrieb: > On 01/15/2010 07:10 PM, Uli Kleinwechter wrote: >> Dear all, >> >> I'm looking for a way to replace NA's with 0 for a number of variables >> which share the same ending and which constitute a subset of a data >> frame. >> >> Say, for example, there is >> >>> data<- data.frame(a

Re: [R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Johannes Signer
Hi, this works aswell: for(i in 1:ncol(data)) data[is.na(data[,i]),i] <- 0 i am sure there is way doing it with a member of the apply family, maybe someone else has an idea. Johannes On Fri, Jan 15, 2010 at 9:51 PM, Jim Lemon wrote: > On 01/15/2010 07:10 PM, Uli Kleinwechter wrote: > >> Dea

Re: [R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Jim Lemon
On 01/15/2010 07:10 PM, Uli Kleinwechter wrote: Dear all, I'm looking for a way to replace NA's with 0 for a number of variables which share the same ending and which constitute a subset of a data frame. Say, for example, there is data<- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1) , ay=c(

[R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Uli Kleinwechter
Dear all, I'm looking for a way to replace NA's with 0 for a number of variables which share the same ending and which constitute a subset of a data frame. Say, for example, there is > data <- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1) , ay=c(5,NA,2,NA,0) , by=c(4,2,NA,2,1)) > data ax bx a