I am loading a csv into a dataframe using
str <- readLines("Messages.csv", n=-1, skipNul=TRUE)
matches <- str_match(str, pattern = "\\s*([0-9]{2}/[0-9]{2}/[0-9]{4}),\\s*([0-9]{2}:[0-9]{2}:[0-9]{2}),\\s*(Me|Them),\\s*(\\+[0-9]{11,12}),\\s*((?s).*)")
df <- data.frame(matches[, -1], stringsAsFactors=F)
colnames(df) <- c("date","time","sender","phone number","msg")
# Format the date and create a row with the number of characters of the messages
df <- df %>%
mutate(posix.date=parse_date_time(paste0(date,time),"%d%m%y%H%M%S"),tz="Europe/London") %>%
mutate(nb.char = nchar(msg)) %>%
select(posix.date, sender, msg, nb.char) %>%
arrange(as.numeric(posix.date))
I can change sender names using
# Change the senders' names
df <- df %>%
mutate(sender = replace(sender, sender == "Me", "Mr. Awesome"))
But I want to change the time zone for the data from to tz="America/Los_Angeles"
I have tried the follow both without success:
attributes(df)$tz<-"America/Los_Angeles"
this compiles but nothing seems to change
and also this:
df <- df %>%
mutate(date = replace(date, format(date, tz="America/Los_Angeles",usetz=TRUE)))
which gives the error: "Error in eval(expr, envir, enclos) : argument "values" is missing, with no default"
Perhaps I am not specifying the original time zone correctly, but I have no idea really how to check that it went through.
Thanks!