After converting data from string , it shows a values as NA.

#changing data type from string to date and time
calories$ActivityMinute <- as.POSIXct(calories$ActivityMinute, format="%Y/%m/%d %H:%M:%S", tz="UTC")
heart_rate$Time <- as.POSIXct(heart_rate$Time, format="%Y/%m/%d %H:%M:%S", tz="UTC")
steps$ActivityMinute <- as.POSIXct(steps$ActivityMinute, format="%Y/%m/%d %H:%M:%S", tz="UTC")
#check if changes has been made correctly
class(calories$ActivityMinute)
class(heart_rate$Time)
class(steps$ActivityMinute)

At first when i ran this on r markbook it worked perfectly fine but now it shows NA in that column.

sample of data Calories data set
ID TIME VALUE
|1|2022484408|4/12/2016 7:21:00 AM|97||
|2|2022484408|4/12/2016 7:21:05 AM|102||
|3|2022484408|4/12/2016 7:21:10 AM|105||
|4|2022484408|4/12/2016 7:21:20 AM|103||
|5|2022484408|4/12/2016 7:21:25 AM|101||
|6|2022484408|4/12/2016 7:22:05 AM|95||

Welcome to the forum.

We need a reproducible example (reprex)

The sample data you have posted has a %d/%m/%Y %H:%M:%S format, not %Y/%m/%d %H:%M:%S, If I change that everything works as expected.

# Sample data in a copy/paste friendly format, replace this with your own data frame
calories <- data.frame(
  stringsAsFactors = FALSE,
                ID = c(2022484408,2022484408,
                       2022484408,2022484408,2022484408,2022484408),
              TIME = c("4/12/2016 7:21:00 AM",
                       "4/12/2016 7:21:05 AM","4/12/2016 7:21:10 AM",
                       "4/12/2016 7:21:20 AM","4/12/2016 7:21:25 AM","4/12/2016 7:22:05 AM"),
             VALUE = c(97, 102, 105, 103, 101, 95)
)

# Relevant code
calories$TIME <- as.POSIXct(calories$TIME, format="%d/%m/%Y %H:%M:%S", tz="UTC")

calories
#>           ID                TIME VALUE
#> 1 2022484408 2016-12-04 07:21:00    97
#> 2 2022484408 2016-12-04 07:21:05   102
#> 3 2022484408 2016-12-04 07:21:10   105
#> 4 2022484408 2016-12-04 07:21:20   103
#> 5 2022484408 2016-12-04 07:21:25   101
#> 6 2022484408 2016-12-04 07:22:05    95

Created on 2022-01-18 by the reprex package (v2.0.1)

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.