r - Converting string to numeric -
this question has answer here:
i've imported test file , tried make histogram
pichman <- read.csv(file="picman.txt", header=true, sep="/t") hist <- as.numeric(pichman$ws) however, different numbers values in dataset. thought because had text, deleted text:
table(pichman$ws) ws <- pichman$ws[pichman$ws!="down" & pichman$ws!="nodata"] however, still getting high numbers have idea?
i suspect having problem factors. example,
> x = factor(4:8) > x [1] 4 5 6 7 8 levels: 4 5 6 7 8 > as.numeric(x) [1] 1 2 3 4 5 > as.numeric(as.character(x)) [1] 4 5 6 7 8 some comments:
- you mention vector contains characters "down" , "nodata". expect/want
as.numericthese values? - in
read.csv, try using argumentstringsasfactors=false - are sure it's
sep="/t, notsep="\t" - use command
head(pitchman)check first fews rows of data - also, it's tricky guess problem when don't provide data. minimal working example preferable. example, can't run command
pichman <- read.csv(file="picman.txt", header=true, sep="/t")since don't have access data set.
Comments
Post a Comment