Skip to content
Prev 261694 / 398502 Next

Help in a project

Hello,

three commands might do the job (NOTE: df=your data frame, 
obser=Observation, var1=Variable 1 [TYPE: string], var1flag=Variable 1 
flag [TYPE: string])

1. df$var1flag<-NA
2. df$var1flag[ is.na(as.numeric(df$var1)) ]<-df$var1[ 
is.na(as.numeric(df$var1)) ]
3. df$var1<-as.numeric(df$var1)

{Please note: Var1 must be type string at the beginning. Otherwise this 
would not work (you cannot have an "A" in a numeric column...)]

After this, 'df' gives:

 > df
   obser var1 var1flag
1     1 1000     <NA>
2     2 <NA>        A
3     3  631     <NA>

Is this what You are looking for?

HTH,
Kimmo
02.06.2011 18:28, Tarun Manchanda wrote: