'How to convert timestamp to date in each row of a column in R?

I have a column which list timestamps and I am in need of converting that to corresponding date for all rows in that column. Listing the code below

app21_csv <- read.csv(file = 'myuser_app21.csv')
app21 <- app21_csv %>%
  mutate(app21_date = as.POSIXct(1513351000000 / 1000, origin = "1970-01-01"))

This is what I tried. But this list same date and time for every rows. I want to check each row of that "timestamp" column and convert to corresponding date. There is nearly 500k rows in timestamp column.

Below code is the sample of timestamp data set.

head(app21_csv$timestamp)
[1] 1.513199e+12 1.513199e+12 1.513200e+12 1.513200e+12 1.513200e+12 1.513202e+12 1.513202e+12


Solution 1:[1]

Change 1.513199e+12 to timestamp

app21_csv <- read.csv(file = 'myuser_app21.csv')
app21 <- app21_csv %>%
  mutate(app21_date = as.POSIXct(timestamp / 1000, origin = "1970-01-01"))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Siddharth