Why operator invalid for atomic vector?

dpo <- dpo[dpo$SERVICE_DATE >= sDate & dpo$SERVICE_DATE <= eDate, ]
qry <- paste("SELECT * FROM apc_correlated WHERE (CONVERT(varchar(10), transit_date_time,121)) >= ", "'",sDate, "'"," AND (CONVERT(varchar(10), transit_date_time,121)) <= ", "'",eDate, "'",sep ="")
dbQ <- sqlQuery(orb, qry)

dpo <- dpo[!is.na(dpo$VEHICLE), ]
dpo <- dpo[dpo$LDATE > 0, ]
dbQ <- dbQ[dbQ$current_route_id > 0, ]
Error in dbQ$current_route_id : $ operator is invalid for atomic vectors

its simply a stipulation of the $ infix function.
the nearest equivalent [ ] square brace syntax, does allow for picking a named item from a container a little more forgivingly.
I think your issue though should be addressed by asking you to reflect on what dbQ is ? what is returned from sqlQuery when it succeed, and when it fails ?
The documentation tells me, when it succeeds it contains a data.frame, when it fails it returns a character string.
I expect you are working with a character string.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.