r - RMySQL: Transforming extracted data -
i trying extract numeric data database columns have been set varchar(100)
. data in relevant columns numeric there shouldn't problem extracting data formatted integer. there nice way in r?
here got:
m_df <- dbgetquery(conn, paste("select ", direc, " position, ", power, " power ", table, " d left join files f on f.id=d.fileid parc='", parc, "' , timestamp >= '", w_date[1], "' , timestamp <= '", w_date[2], "' , plantnumber = ", w_mach, sep=""))
executing following:
sum(m_df$power)
produces error:
error in sum(m_df$power) : invalid 'type' (character) of argument
performing:
str(m_df)
generates:
'data.frame': 4317 obs. of 2 variables: $ position: chr "280" "281" "288" "294" ... $ power : chr "294" "342" "324" "284" ...
you trying sum characters , r saying "whaaaa?". little snippet follows reproduces error.
(x.char <- sum(c("1", "2", "3"))) error in sum(c("1", "2", "3")) : invalid 'type' (character) of argument (sum(as.numeric(x.char))) [1] 6
run as.numeric
function on data.frame , you're go.
Comments
Post a Comment