php - as.numeric is not working -


i developing code r , trying integrate php. in code after as.numeric, values output na on logs.txt , n = '"15","20","30","40","50"'; (coming php)

# my_rscript.r  args <- commandargs(true) n <- args[1]  n=c(n)  cat(n,file="c:/rlogs.txt",append=true)  n=as.numeric(as.character(n))  cat(n,file="c:/rlogs.txt",append=true)  png(filename="temp.png", width=500, height=500) hist(n, col="lightblue") dev.off() 

i appreciate on this.

without more detail, first need convert input single string vector.

that is, need strsplit, , in case gsub rid of quotation marks:

n <- '"15","20","30","40","50"'  as.numeric(n) # [1] na # warning message: # nas introduced coercion   n <- strsplit(n, ',')[[1]] n # [1] "\"15\"" "\"20\"" "\"30\"" "\"40\"" "\"50\""  n <- gsub('"', '', n) n # [1] "15" "20" "30" "40" "50"  n <- as.numeric(n) n # [1] 15 20 30 40 50 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -