Reputation: 4686
I have a list "list.of.df" containing 3 data frames, that I coerce into a single data frame containing columns of all data frames using ldply
from plyr
package i.e.
df <- ldply(list.of.df)
This approach used to work, but today I have a new set of data and I received an error
Error in as.POSIXct.numeric(what, tz = tzone) : 'origin' must be supplied
There are a few POSIXct
variables in the 3 data frames, so it may be a bit meddlesome to manually troubleshoot everytime I have a new set of data. Instead, is there a way for me to pass the origin
required in the ldply
call?
The list can be load
ed from the dropbox link here.
Upvotes: 0
Views: 444
Reputation: 171
The reason for the error is that the "BILLING SUBMISSION" column has dates in your first two list elements(which are dataframes), but has a numeric column in the last dataframe. ldply is trying to do an implicit conversion of the numeric value to a POSIX date value using the as.POSIX family of functions and to do that, an origin needs to be explicitly specified. See a solutions below:
Make sure all the datatypes in each dataframe you are trying to merge are the same or similar. You can achieve this with the code below using lapply to loop through your list:
load(list.of.df)
b <- lapply(list.of.df, function(x){
x[, "BILLING SUBMISSION"] <- as.POSIXct(x[, "BILLING SUBMISSION"], origin = "1970-01-01"); return(x)})
df <- ldply(b)
You should probably change your column names to proper R column names just to be safe in the future. Hope this helps.
Upvotes: 3