-2

MYCODE

setwd("~/R/Scripts - todos/Dolar")
dolardia <- read.xlsx ("com3500.xlsx", sheet = "Hoja1")
view(dolardia$FECHA)
str(dolardia$FECHA)

col1 <- as.Date(dolardia$FECHA, format= "%d/%m/%y")

THE PROBLEM

col1 <- as.Date(dolardia$FECHA, format= "%d/%m/%y")

Error in as.Date.numeric(dolardia$FECHA, format = "%d/%m/%y"):
'origin' must be supplied

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • 1
    Try col1 <- as.Date(dolardia$FECHA, format= "%d/%m/%y", origin = "1970-01-01"). – Levon Ipdjian Jan 29 '21 at 18:29
  • it´s don´t have an error, but the information is not correct. because when i try to see it with a view(col1), show me NA for all obs – Dieguexs Jan 29 '21 at 18:57
  • Maybe `col1 <- as.Date(as.character(dolardia$FECHA), format= "%d/%m/%y")` will work? It's hard to say without out a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). What does `class(dolardia$FECHA)` return? – MrFlick Jan 29 '21 at 19:31
  • Hola Dieguexz. Could you please paste the output that the following code will generate? dput(head(dolardia)) – Nicolás Velasquez Jan 29 '21 at 19:55
  • No me deja pegar o adjuntar imagenes... – Dieguexs Jan 29 '21 at 19:57
  • Pero puedes editar el texto y pegar el resultado de dput(). – Nicolás Velasquez Jan 29 '21 at 19:57
  • 1
    It would be very useful to put an example of the dates that you're trying to parse. There have been several answers and you haven't put a MWE yet. – Ondino Jan 30 '21 at 04:22

1 Answers1

0

If the date is recent (i.e. after Unix epoch - January 1st, 1970), you could try

col1 <- as.Date(dolardia$FECHA, format= "%d/%m/%y", origin = "1970-01-01")
Nicolás Velasquez
  • 5,623
  • 11
  • 22