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:
To whom it may concern,
I am a new user to R and I need help in my if and for statements as I need a 
place marker.

I would like to convert the following table:
Observation | Variable 1
--------------------|-------------
1 | 10000
2 | A
3 | 631

Into :
Observation| Variable 1 | Variable 1 Flag
----------------|------------------|------------------
1 |  10000 | NA
2 | NA | A
3 | 631 | NA


please note |  represents another column.

______________________________________________
R-help@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.

Reply via email to