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.numeric these values?
  • in read.csv, try using argument stringsasfactors=false
  • are sure it's sep="/t , not sep="\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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -