[R] replacing <NA> in character column

Mark Miller mark_wayne_miller at yahoo.com
Wed Oct 28 22:19:49 CET 2009

I have a small Excel data file with two columns of character variables, one column with a numeric variable and three rows.  One of the character cells is blank and one of the numeric cells is blank.

I read the data file with the following code:


channel <- odbcConnectExcel('u:/test.xls')

s1 <- sqlFetch(channel, "Sheet1")



The code prints the data file as:

  Firstname  Lastname Age
1    Bob       Smith   20
2   John       Clark   NA
3   Andy       <NA>    40

I can replace the NA with the number zero in the second row of the third (‘Age’) column using the following line:

s1[is.na(s1[,3]), 3] <- 0

What code can I use to replace the <NA> in the third row of the second (‘Lastname’) column with qqqqqqqq?

Thank you in advance for any advice.

Mark Miller
Gainesville, Florida

More information about the R-help mailing list