0

I was trying to replace the na values in all rows of a column with a specific character. The column name is called 'morph'. I tried to replace na values with the character 'nul' and the R code I tried is:

data$morph[which(is.na(data$morph))] <- nul. 

An error turned out indicating that

"Error: object 'nul' not found".

What's wrong with my code and how to fix it? Thanks for answering my questions.

akrun
  • 874,273
  • 37
  • 540
  • 662
Alex Fang
  • 9
  • 1
  • 2
    I don't know that you can use a literal `nul` (0-byte) in R without a bit of kludge work ... otherwise, please make this question *reproducible. This includes sample code you've attempted (including listing non-base R packages, and any errors/warnings received), sample *unambiguous* data (e.g., `dput(head(x))` or `data.frame(x=...,y=...)`), and intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans May 29 '20 at 00:30

1 Answers1

0

If we need to replace then use a character string

data$morph[which(is.na(data$morph))] <- "null" 
akrun
  • 874,273
  • 37
  • 540
  • 662