Hi all I have a list of multiple datframes with the same column headers. The last column in each datframe contains a vector of "Interval" class after I have produced this column using "lubridate" package. I needed to convert my list of dataframes to be in a single dataframe for further analysis. I did this using the following syntax : SingleDataframe <- ldply (MylistofDFs,data.frame) The problem is that after this conversion, the the column with time intervals has been converted into numeric type with number of seconds during the time interval instead of the interval itself as follows : The column Before conversion looks like this: TimeInterval (class 'interval') 2012-12-13 UTC--2016-02-16 UTC but after conversion the list into dataframe, This column becomes number of seconds as follows : TimeInterval (class : numeric) 100224000 Is there any method to convert my list into a a single dataframe without affecting the types of vectors in my dataframes?. i.e. I want to keep the interval column as it with avoidance its conversion into numeric when I convert my list of dataframes into a single dataframe... Or at least keep the same format of the interval even if this has been changed to "character" type vector even though I prefer to be in "interval" class. Any suggestions would be very appreciated. Regards [[alternative HTML version deleted]]
> On Apr 17, 2018, at 10:10 AM, Allaisone 1 <allaisone1 at hotmail.com> wrote: > > > Hi all > > I have a list of multiple datframes with the same column headers. The last column in each datframe contains a vector of "Interval" class after I have produced this column using "lubridate" package. I needed to convert my list of dataframes to be in a single dataframe for further analysis. I did this using the following syntax : > > SingleDataframe <- ldply (MylistofDFs,data.frame) > > The problem is that after this conversion, the the column with time intervals has been converted into numeric type with number of seconds during the time interval instead of the interval itself as follows : > > The column Before conversion looks like this: > > TimeInterval (class 'interval') > 2012-12-13 UTC--2016-02-16 UTC > > but after conversion the list into dataframe, > This column becomes number of seconds as follows : > > TimeInterval (class : numeric) > 100224000 > > Is there any method to convert my list into a a single dataframe without affecting the types of > vectors in my dataframes?. i.e. I want to keep the interval column as it with avoidance its conversion into numeric when I convert my list of dataframes into a single dataframe... Or at least keep the same format of the interval even if this has been changed to "character" type vector even though I prefer to be in "interval" class.There is no base R class called "interval". Perhaps lubridate has not provided you with an `ldply( . ,data.frame)`-accessible method for concatenation. You should construct an example that starts with the loading code for whatever package(s) are being used.> > Any suggestions would be very appreciated. > > Regards > > [[alternative HTML version deleted]] >You should also read the Posting Guide.> ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius Alameda, CA, USA 'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary to Clarke's Third Law
Many thank David .., Yes , correct, the class "interval" is a special class belongs to the package "lubridate" and is not a base R class. I have just found a solution and happy to share it :- using an alternative conversion method with the use of "rbind" instead of "ldplyr " method will keep the converted dataframe with the same "interval' class as follows :- MySingleDF <- do.call("rbind",MyList) Regards ________________________________ From: David Winsemius <dwinsemius at comcast.net> Sent: 17 April 2018 21:10:43 To: Allaisone 1 Cc: r-help at r-project.org Subject: Re: [R] Time intervals in a datframe> On Apr 17, 2018, at 10:10 AM, Allaisone 1 <allaisone1 at hotmail.com> wrote: > > > Hi all > > I have a list of multiple datframes with the same column headers. The last column in each datframe contains a vector of "Interval" class after I have produced this column using "lubridate" package. I needed to convert my list of dataframes to be in a single dataframe for further analysis. I did this using the following syntax : > > SingleDataframe <- ldply (MylistofDFs,data.frame) > > The problem is that after this conversion, the the column with time intervals has been converted into numeric type with number of seconds during the time interval instead of the interval itself as follows : > > The column Before conversion looks like this: > > TimeInterval (class 'interval') > 2012-12-13 UTC--2016-02-16 UTC > > but after conversion the list into dataframe, > This column becomes number of seconds as follows : > > TimeInterval (class : numeric) > 100224000 > > Is there any method to convert my list into a a single dataframe without affecting the types of > vectors in my dataframes?. i.e. I want to keep the interval column as it with avoidance its conversion into numeric when I convert my list of dataframes into a single dataframe... Or at least keep the same format of the interval even if this has been changed to "character" type vector even though I prefer to be in "interval" class.There is no base R class called "interval". Perhaps lubridate has not provided you with an `ldply( . ,data.frame)`-accessible method for concatenation. You should construct an example that starts with the loading code for whatever package(s) are being used.> > Any suggestions would be very appreciated. > > Regards > > [[alternative HTML version deleted]] >You should also read the Posting Guide.> ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius Alameda, CA, USA 'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary to Clarke's Third Law [[alternative HTML version deleted]]