Saving time stamps into a new column of an existing data frame

Hi R community members,

I'm pretty new to working with time stamps in R.
When I want to add new info to an existing data frame I usually create a vector with the info I want to add into the new column and then add it to the data frame as follows:

vecWithNewInfo <- c("Value1","Value2","Value3")
dataFrame$newCol <- vecWithNewInfo

It did what I intend to achieve, for all classes I worked with so far - characters, numericals... However, if I try to do the same with time stamps (class: "POSIXlt" "POSIXt") it doesn't work properly. Trying to add the time stamps they way I mentioned above to the data frame leads to that every value of the column is a list. When I initialize a new data frame with a column containing time stamps the time stamps are not saved as lists and just as a single time stamp value with the class "POSIXlt" "POSIXt" (that's the way I want it to be).

newDataFrame <- data.frame("Temperature_degC"=35.5,"TimeStamp"=strptime("21.03.2022 15:28:55",format="%d.%m.%Y %H:%M:%S"))

Is there any explanation for this behavior or a way to achieve the same outcome that is created by the new creation of a data frame when adding new values (multiple time stamps) to an existing data frame?
I hope that you can help me. If I was not understandable, I'm open to answer any questions.

Best regards
Max

(newDataFrame <- data.frame("Temperature_degC"=c(35.5,
                                                 70)))

(vecWithNewInfo <- strptime(c("21.03.2022 15:28:55",
                              "04.01.2023 15:28:55"),
                            format="%d.%m.%Y %H:%M:%S"))

newDataFrame$TimeStamp <- vecWithNewInfo
newDataFrame

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.