Menu
  • HOME
  • TAGS

Trouble converting and separating dates in R

r,excel,date,date-conversion,as.date

If all your dates are in the last 14 years, then this should work: dat$dat2 <- gsub("/([0-9]{2})$", "/20\\1", dat$date) library(lubridate) dat$dat3 <- dmy(dat$dat2) The gsub function will ignore teh items that do not have exactly 2 digits between a forward-slash and the end of the string. If you have some...

convert string data.frame to Date

r,string,dataframes,as.date

You need to use two [ brackets. With one, the column remains as a data frame. With two, it becomes an atomic vector which can properly be passed to the correct as.Date method as.Date(df["Date"], "%m/%d/%Y") # Error in as.Date.default(df["Date"], "%m/%d/%Y") : # do not know how to convert 'df["Date"]' to...

R: Setting limits to scale_x_yearqtr in ggplot for yearqtr (zoo)

r,ggplot2,time-series,zoo,as.date

I think you just didn't specify the limits properly. In addition, to achieve greater control over the appearance, use the breaks argument (rather than n). # some data df <- data.frame(x = as.yearqtr(2004 + seq(3, 8)/4), y = sample(1:6)) # setting limits only ggplot(data = df, aes(x, y, group =...

Transforming as.Date: multiple data frames at once

r,as.date

Try lst <- lapply(mget(ls(pattern='^dat2003q\\d+')), function(x) { x$Date <- as.Date(as.character(x$Date), format='%m/%d/%Y') x}) If you want to update the datasets in the global environment with this change (which is not that recommended as you can do all the necessary operations within the list and later you may save the datasets using read.table)...

R: reorder data after split() command using unconventional date column

r,split,order,as.date

Convert the names to time format, reorder and reorder list by index. dat[order(strptime(names(dat), "%B %d %H"))]...

Paste Date to Time in an Irregular Way

r,plyr,as.date

If you need a date-time object library(data.table) setDT(df)[, as.POSIXct(paste(v1[1], v1[-1]), format='%Y-%m-%d %H:%M'), by=gr] # gr V1 #1: 1 2014-12-01 07:00:00 #2: 1 2014-12-01 08:00:00 #3: 1 2014-12-01 09:00:00 #4: 2 2014-12-02 06:00:00 #5: 2 2014-12-02 09:00:00 Or if you need it to be in the format as shown in the...

R script working locally not working on shinyapp.io

r,shiny,as.date

You have two problems. First, you missed some quotes in your data. However, fixing that did not change the result. I copied your code, fixed the quotes, and deployed it and got the same results (worked locally but not on shinyapps.io). The second (and more important problem) is with the...

Dates on x-axis, time series

r,date,time-series,as.date

I had to augment your example to get something to play with, but here is something that works. And I just changed it to eliminate lubridate... library(xts) d1 <- seq(as.Date("2001-01-01"),as.Date("2021-01-01"),"years") d2 <- rnorm(21,10,1) Dollar <- data.frame(d1,d2) dates <- as.Date(Dollar[,1], "%d.%m.%Y",tz="GMT") xtsplot <- as.xts(Dollar[,2], dates) plot(xtsplot, xaxt = "n", main="SMA", ann...