I am using DBI package to insert data to MySQL. Here is the code:
ch <- DBI::dbConnect(MySQL())
dbSendQuery(ch, 'set character set "utf8"')
dbSendQuery(ch, 'SET NAMES utf8')
for (i in 1:nrow(test)) {
query <- paste0("INSERT INTO trade_data VALUES('0', '", test[i, 1], "', '",
test[i, 2], "', ", test[i, 3], "')")
dbSendQuery(ch, query)
}
The problem is in 3td column, which is numeric, but have NA
values. When loop comes to row which has NA
value it returns an error:
Error in .local(conn, statement, ...) : could not run statement: Unknown column 'NA' in 'field list'
I tried to change NA to NaN, "NULL", and some other types, but nothing works. If I change NA to 0 it works.