unable to convert char to date using as.Date() in R [closed] - r

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 days ago.
Improve this question
I'm lost : i'd like to convert chararcter to date using as.Date() in R. I genuinely don't know what i missed with such a simple code. Here is an example
week_dates <- as.Date("06/20/2022", format ="%d/%m/%Y")
week_dates return only NA. Any idea what i missed ?
Thanks in advance !

Related

How to use toString in R [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
When I am running the following lines, there is an error saying Error in toSrting(m) : could not find function "toSrting". I have no idea what happened since toString usually works well but not here:
m <- 1
for(m in 1:60000){
toSrting(m)
paste("trainxr", m) <- raster(trainxr[m,,])
strtoi(m)
m <- m + 1
}
Thank you for your help.
I've never used R but I think string is spelled wrong.

How to fix this function? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am doing an exercise to create a function. One of the questions is:
"We can estimate the cumulative risk of an certain event using the
exponential formula
1-exp(-1/10000*t) where t is the time to the event. Create a function ans(t), which returns the risk at time t.
and I am using this command:
function(t){ans(t)<-1-exp(-1/10000*t)return(ans(t))}
but it is giving wrong answer. Can someone help me to understand this please?
The proper format to define a function is this:
ans<-function(t){
answer<-1-exp(-1/10000*t)
return(answer)
}
ans(1)
#[1] 9.9995e-05

Error: unexpected SPECIAL in "as.Date(20110505, %Y%" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am not sure why I cannot do write the following code.
as.Date(20110505, %Y%m%d)
I receive the error given in the title. Can anyone help me out?
It should be string with the format also in quotes
as.Date(as.character(20110505), "%Y%m%d")
#[1] "2011-05-05"

has the %between% command in R been removed? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am returning to some old code where I had used the following syntax:
y[df$myvar %between% c(1,100)]
but get the error
could not find function "%between%"
This code used to work, and I have updated R in the mean time. any thoughts?
As Pascal pointed out, you should load the package data.table first:
library(data.table)
Then you'll be able to use it.

Date conversion in R not registering string correctly [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Can someone please tell me why this doesn't work:
as.Date("01/08/15", format = "%m/%d/%Y")
[1] "0015-01-08"
Thanks!
You need to use lower-case %y. Upper-case %Y requires a 4-digit year. (In my opinion, the entire command should have failed with an error message, but unfortunately it didn't.) See strptime(), which documents the format codes.
as.Date("01/08/15", format = "%m/%d/%y")
## [1] "2015-01-08"

Resources