我正在尝试从列已设置为的数据库中提取数字数据VARCHAR(100)
。相关列中的所有数据都是数字,因此提取格式化为整数的数据应该没有任何问题。在R中有一个很好的方法来做到这一点吗?
这是我得到的:
m_df <- dbGetQuery(conn, paste("SELECT ", direc, " as Position, ", power, " as Power FROM ", table,
" d LEFT JOIN files f on f.id=d.fileid WHERE parc='", parc,
"' AND timestamp >= '", w_date[1], "' and timestamp <= '", w_date[2],
"' AND plantnumber = ", w_mach, sep=""))
执行以下操作:
sum(m_df$Power)
产生此错误:
Error in sum(m_df$Power) : invalid 'type' (character) of argument
表演:
str(m_df)
生成:
'data.frame': 4317 obs. of 2 variables:
$ Position: chr "280" "281" "288" "294" ...
$ Power : chr "294" "342" "324" "284" ...