Subtracting Columns in R

219 views Asked by At

I have two columns I am trying to subtract and put into a new one, but one of them contains values that read '#NULL!', after converting over from SPSS and excel, so R reads it as a factor and will not let me subtract. What is the easiest way to fix it knowing I have 19,000+ rows of data?

1

There are 1 answers

0
akrun On BEST ANSWER

While reading the dataset using read.table/read.csv, we can specify the na.strings argument for those values that needs to be transformed to 'NA' or missing values. So, in your dataset it would be

dat <- read.table('yourfile.txt', na.strings=c("#NULL!", "-99999", "-88888"),
      header=TRUE, stringsAsFactors=FALSE)