Reputation: 55
I am trying to make back trajectory plots in openair package (R), using data I have made myself (using Hysplit and R/openair).
I get an error: "Error in abs(mydata$len) : non-numeric argument to mathematical function".
My code (reading in trajectory data straight from csv file):
# read in trajectory
mydata <- read.csv("c:/hysplit4/working/2014/2014rml.csv", header = TRUE,
stringsAsFactors = FALSE # I have tried with /without this line
)
# make sure dates are read correctly
mydata$date2 <- as.POSIXct(strptime(mydata$date2, format = "%Y-%m-%d %H:%M:%S"))
mydata$date <- as.POSIXct(strptime(mydata$date, format = "%Y-%m-%d %H:%M:%S"))
as.vector(as.matrix(mydata)) # I have tried with/ without this line
# plot trajectory for specific dates
library(openair)
library(mapdata)
trajPlot(mydata)`
Alternate code I have tried - reads in the .Rdata file created by 'ProcTraj' as detailed in appendix of 'openair' manual. When opend in Rstudio, the resulting 'mydata' looks identical (as shown below):
mydata <- importTraj(site = "SuvaCity", year = 2014,
local = "C:/HYSPLIT/TrajProc/")
## at this point it prints the trajectory data on the screen and it looks fine
trajPlot(mydata)
This gives the error:
"Error in as.POSIXlt.character(mydata$date[1]) : character string is not in a standard unambiguous format"
if I add in:
mydata$date2 <- as.POSIXct(strptime(mydata$date2, format = "%Y-%m-%d %H:%M:%S"))
mydata$date <- as.POSIXct(strptime(mydata$date, format = "%Y-%m-%d %H:%M:%S"))
I am back to the original error.
mydata:
receptor,year,month,day,hour,hour.inc,lat,lon,height,pressure,date2,date
1,2014,1,1,0,0,-18.134,178.424,18,1000.2,2014-01-01 00:00:00,2014-01-01 00:00:00
1,2013,12,31,23,-1,-18.089,178.532,30,998.6,2013-12-31 23:00:00,2014-01-01 00:00:00
1,2013,12,31,22,-2,-18.045,178.659,44.5,996.9,2013-12-31 22:00:00,2014-01-01 00:00:00
1,2013,12,31,21,-3,-18.002,178.806,61.5,995.3,2013-12-31 21:00:00,2014-01-01 00:00:00
1,2013,12,31,20,-4,-17.96,178.97,80.6,993.3,2013-12-31 20:00:00,2014-01-01 00:00:00
1,2013,12,31,19,-5,-17.92,179.151,100.5,990.4,2013-12-31 19:00:00,2014-01-01 00:00:00
1,2013,12,31,18,-6,-17.885,179.352,120.3,988,2013-12-31 18:00:00,2014-01-01 00:00:00
Upvotes: 0
Views: 1388
Reputation: 3
There seems to be no problem with your.Rdata file contents. The date format of mydata shouldn't be a problem. However you can try using:
mydata$date=as.character(mydata$date)
mydata$date=as.POSIXct(mydata$date,tz="GMT")
Upvotes: 0