I have several hundred text files that I'm scanning in as matrices. I have discovered that some of the files have ******
instead of a number in some locations. This causes an error: scan() expected 'a real', got '******'
. Is there a way to scan these files in as a matrix and replace the ******
with a number such as 0?
Edit: with the help I received, I was able to solve the issue like this:
dat_test <- read.table("test.txt", na.strings = "******")
dat_trans <- matrix(dat_test[,3], 141, byrow=FALSE)
dat_trans[is.na(dat_trans)] <- -32768
My data is in one really long column so the second line above transposes it in the format I need to analyze it.