Troubles in R with Dates - r

I'm just starting with R. I have the following problem:
I am using the "sesonal" package (http://cran.at.r-project.org/web/packages/season/season.pdf). I wanted to usethe cosinor function but I have a problem I can't solve.
If I use this call:
test = cosinor(data=train_data2, date=as.Date("2013-01-01"))
I get:
Fehler in charToDate(x) :
character string is not in a standard unambiguous format
but the date seams to be in the right format since
as.Date("2013-01-01")
works fine.
can anyone help me ?
Thanks in advance!

Related

How to solve the following error message related to dates :Incompatible methods ("-.Date", "-.POSIXt") R?

I am new using R, I need to calculate the time between two dates: date_inclusion and date_point, for which I am doing the following.
cancer$date_point <- as_date("1980 - 02 - 15")
cancer$delai_recul_j <-(cancer$date_point-cancer$Date_inclusion)
but I get the following message.
'Warning message: Incompatible methods ("-.Date", "-.POSIXt") for "-"'
At first I thought it was the Mac date format, but it didn't work, I don't know what to do, since obviously with the column that is created I can't work.
Thank you very much!

R I would like to record an empty data entry using as.Date

R - I would like to input an empty data entry using as.Date. If I enter in the R console as.Date(""), I get NA as a return without any error message.
When I used as.Date() inside a loop, I got an error message to ask me to supply the 'origin'. But when I included the 'origin' argument in the as.Date function, as you can see below, I still get an error message.
I don't understand what I am doing wrong. I would appreciate any help on this. Many thanks!
for (r in 1:nrow(R3)){
R3$DATE1[r]<-ifelse(
R3$dateDiff2[r]==R3$MIN[r],
RR3$DATE1[r],
as.Date("", origin="1970-01-01")
)
}
<Error in as.POSIXct.numeric(value) : 'origin' must be supplied

CharToDate(x) Error in R

I have a function named currency. It takes a parameter A which is a currency like "EUR/USD" . Then I do this: n<-getSymbols(A,src = "oanda",from = "2016-01-01",to = Sys.Date(),auto.assign = FALSE)
The paradox is that the program was running fine 2 days ago.
The error message is: Error in charToDate(x) : character string is not in a standard unambiguous format.
This is the traceback()
Thanks in advance!
I think that this a duplicate
quantmod::getFX function returns "character in a standard unambiguous format"
In any case, I followed the code of the getSymbols.oanda and it seems that oanda changed their API so instead of downloading a .csv you get a .xml file.
Speaking for me, I will go for a different source for the data until this is resolved by the quantmod guys.

R - Error in charToDate(x)

I'm sure this is super simple to understand, but I'm new to R, and try as I might, I can't get the other suggestions on these forums to work for me. I'm just trying to download the PAYEMS time series through the Quantmod package.
The code:
library(quantmod)
library(lubridate)
getSymbols("PAYEMS", src=("FRED"), return.class = "xts")
The output:
getSymbols("PAYEMS", src=("FRED"), return.class = "xts")
Error in charToDate(x) :
character string is not in a standard unambiguous format
I'm guessing it's the date format, but it's not clear to me how I fix that. I only know how to change it once I get the vector I want to make into dates.
Thanks!
I get this error occasionally too. I don't recall getting this the year before. Restarting R doesn't help, but restarting the computer does solve the problem. I don't know what it is that fixed this.

Changing String to Date and Time in R

I have a vector of character class strings.
I want to covert this to Sys.time() format. How can I do that?
When I use the as.POSIXct(z,format= "%d/%m/%Y %H:%M:%S")
I get the following warning:
Warning message:
In as.POSIXlt.POSIXct(x, tz) : NAs introduced by coercion
I don't want this to convert to NAs. What should I do?
Kindly use
strptime("2014-06-05 15:33:55 IST","%Y-%m-%d %H:%M:%S",tz="Asia/Kolkata")
For your problem
data$time <- strptime(data$time, "%Y-%m-%d %H:%M:%S",tz="Asia/Kolkata")
class(data$time)
It should be of type POSIXlt
I know this is an old question but for the benefit of those Googling this problem, I had a similar problem recently when using rbind.fill. I discovered that one of my dates was in European format, 31/1/2017 instead of 1/31/2017 like all the others. It was causing R to blank out the entire column after performing rbind.fill. Fixing the date fixed the issue.
Hope this helps someone, I spent hours trying to figure out why this was happening. R is really picky sometimes.

Resources