dataset - Loading dataframe containing useless characters in R -
i have executable outputs table every time called r. want load dataframe in r, contains lots of "!", instance:
! b c 0 1 2 3 3 2 1 1 1 ! 3 4 2 2 2 3 5 2 5 ! 3 4 2 .....
so get:
sim_stat <- read.table("c:/users/matteo/desktop/forest/formind/formind-model/result/result.dia") # error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : # line 2 did not have 11 elements
i need read data in r every second more or less, there fast way remove "!" ? working in windows. thanks!
you can have !
treated comment character:
read.table(file="...", comment.char="!")
that will rid of header, or other lines extraneous !. if have data in line !, , want ignore ! keep rest, there long workaround:
> read.table(text=gsub("!", "", readchar("test.txt", file.info("test.txt")$size)), header=true) b c 1 0 1 2 2 3 3 2 3 1 1 1 4 3 4 2 5 2 2 3 6 5 2 5 7 3 4 2
obviously replacing "test.txt" file name in both instances, , "!" whatever character(s) ignored.
Comments
Post a Comment