I hope the following problem is not too trivial. I am kind of new to R, so I really appreciate help and advice! I have a data.list with data.frames in the form ot tibbles. Previously I worked with the data.frames on their own. The data.frames that are in xlxs format. This is the structure of a data.frime, before I adjust the column named 'Time':
structure(list(Time = structure(c(-2209074960, -2209074900, -2209074840,
-2209074780, -2209074720, -2209074660, -2209074600, -2209074540,
-2209074480, -2209074420, -2209074360, -2209074300, -2209074240,
-2209074180, -2209074120, -2209074060, -2209074000, -2209073940,
-2209073880, -2209073820), tzone = "UTC", class = c("POSIXct",
"POSIXt")), Kcal = c(1.899, 2.859, 2.519, 2.89, 2.89, 2.88, 3.68,
3.73, 3.07, 4.579, 4.889, 5.449, 9.51, 13.56, 13.63, 14.109,
14.289, 14.38, 14.84, 0.509), MET = c(2.5, 3.3, 3.3, 4.2, 4.6,
4.5, 6.2, 6.9, 7.4, 8.1, 9.5, 10.5, 11.6, 12.2, 12.8, 13.4, 13.8,
14.2, 14.3, 14.5), `MET in Kcal` = c(3.4125, 4.5045, 4.5045,
5.733, 6.279, 6.1425, 8.463, 9.4185, 10.101, 11.0565, 12.9675,
14.3325, 15.834, 16.653, 17.472, 18.291, 18.837, 19.383, 19.5195,
19.7925)), row.names = c(NA, -20L), class = c("tbl_df", "tbl",
"data.frame"))
One of the columns in the data.frame is named 'Time'. The value 'Time' is imported as a character. In order to adjust the Time I apply following code to my data.list:
for(i in seq_along(ErgoWithings_list))
{ErgoWithings_list[[i]]$Time <- gsub("1899-12-31 ","",as.character(ErgoWithings_list[[i]]$Time))}
This works fine so far. As I worked with the data.frame on its own I did following operation, to set 'Time' as a time value:
MyDateTime <- df$Time
MyDateTime <- strptime(MyDateTime, format = "%H:%M:%OS")
MyDateTime <- as.POSIXct(as.numeric(as.POSIXct(MyDateTime)) %% 86400, origin = "2021-09-28")
df$Time <- MyDateTime
This worked fine for me. I tried to apply it now to the whole list:
for(i in seq_along(ErgoWithings_list))
{MyDateTime <- ErgoWithings_list[[i]]$Time
MyDateTime <- strptime(MyDateTime, format = "%H:%M:%OS")
MyDateTime <- as.POSIXct(as.numeric(as.POSIXct(MyDateTime)) %% 86400, origin = "2021-09-28")
ErgoWithings_list[[i]]$Time <- MyDateTime}
However, this does not work, as I get the notice, that '}' is unexpected.
If I try it like that:
for(i in seq_along(ErgoWithings_list))
MyDateTime <- ErgoWithings_list[[i]]$Time
MyDateTime <- strptime(MyDateTime, format = "%H:%M:%OS")
MyDateTime <- as.POSIXct(as.numeric(as.POSIXct(MyDateTime)) %% 86400, origin = "2021-09-28")
ErgoWithings_list[[i]]$Time <- MyDateTime
only the last data.frame in the list changes somehow, but none of the ones before. Could someone help me out with adjusting the time? Additionally, I would ideally want only the given time in the data.frames/tibbles without having also a date (which I set by 'origin =...'). But I don't know how to work around it. Thanks!