Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread arun
  B  0.0  1.0 #6    B  9.0 10.0 A.K. - Original Message - From: soon yi To: r-help@r-project.org Cc: Sent: Thursday, November 15, 2012 2:29 PM Subject: Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers #Data df<-data.fram

Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread soon yi
#Data df<-data.frame(id=letters[1:10],var1=rnorm(10,10,5),var2=rnorm(10,5,2),var3=rnorm(10,1,1)) #Missing df$var1[2]<-df$var2[c(2,6)]<-df$var3[c(2,5)]<-NA na.replace<-seq(1:ncol(df))-1 df[,names(df)]<-sapply(1:dim(df)[2], function(ii) {ifelse(is.na(df[,ii]),na.replace[ii],df[,ii])} ) David Ro

Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread William Dunlap
"four" ... $ Factor : Factor w/ 2 levels "Group A","Group B": 1 1 1 2 2 2 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of

Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread Stendera, Sonja, Dr.
-project.org Betreff: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers Hi everyone, I have a data frame one of whose columns is a character vector and the rest are numeric, and in debugging a script, I noticed that an ifelse call seems to be coe

Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread arun
ursday, November 15, 2012 6:19 AM Subject: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers Hi everyone, I have a data frame one of whose columns is a character vector and the rest are numeric, and in debugging a script, I noticed that an ifel

Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread Bert Gunter
David: You seem to be getting lost in basic R tasks. Have you read the Intro to R tutorial? If not, do so, as this should tell you how to do what you need. If so, re-read the sections on indexing ("["), replacement, and NA's. Also read about character vectors and factors. -- Bert On Thu, Nov 15,

Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread David Romano
Thanks for the suggestion, Bert; I just re-read the introduction with particular attention to the sections you mentioned, but I don't see how any of it bears on my question. Namely -- to rephrase: What constraints are there on the form of the "yes" and "no" values required by ifelse? The introd

[R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread David Romano
Hi everyone, I have a data frame one of whose columns is a character vector and the rest are numeric, and in debugging a script, I noticed that an ifelse call seems to be coercing the character column to a numeric column, and producing unintended values as a result. Roughly, here's what I tried