Closed echriste1950 closed 8 years ago
When importing data, force character to reaming as character and not converted to factor. For dates, convert the Date type using the as.Date function with the correct format for the way that the data are recorded. Also make sure everything that should be numeric is numeric and not intgeger, which can happen if there are no decimal points.
On Wed, May 25, 2016 at 9:47 AM, echriste1950 notifications@github.com wrote:
I was trying to follow one of rloadest vignettes (rloadest~app1) with my own data and it does not recognize the date format. Data are in Excel files and I tried saving them as both comma delimited and text. Original dates were mm/dd/yyyy, but I tried with them reformatted as yyyy-mm-dd and still no luck. I have attached the data in*.txt format. LCMOSELtxt.txt https://github.com/USGS-R/rloadest/files/282219/LCMOSELtxt.txt
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/USGS-R/rloadest/issues/10
I'm becoming a big fan of the function fread
in the data.table
package. It initially brings in the data as a "data.table"...which is a little different than a data frame, but it's easy to switch with the setDF
function. It's a very fast import function, and very good at getting the columns initially correct (I've tested it against the readr
package and base, and it almost always does the best). Anyway, dates can always be tricky, so even then you need to convert:
library(data.table)
data <- setDF(fread("C:/Users/ldecicco/Downloads/LCMOSELtxt.txt"))
data$DATES <- as.Date(data$DATES)
So DATES and TIME are now characters, but when I try:
data$DATES<-as.Date(data$DATES) I get: Error in data$DATES : object of type 'closure' is not subsettable
I wrote the example hastily, and really shouldn't have called your data data
.....my bad. Try this:
library(data.table)
LCMOSEL <- setDF(fread("C:/Users/ldecicco/Downloads/LCMOSELtxt.txt"))
LCMOSEL$DATES <- as.Date(LCMOSEL$DATES)
data
means something in R....
That did it. I probably should have recognized that "data" was a place holder. Thanks.
I was trying to follow one of rloadest vignettes (rloadest~app1) with my own data and it does not recognize the date format. Data are in Excel files and I tried saving them as both comma delimited and text. Original dates were mm/dd/yyyy, but I tried with them reformatted as yyyy-mm-dd and still no luck. I have attached the data in*.txt format. LCMOSELtxt.txt