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
#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
"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
-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
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
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,
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
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
8 matches
Mail list logo