R Extract day from datetime
Since your result will no longer be a date anyway, you could use gsub
gsub("(.*)[-]", "", df$x)
# [1] "24" "24" "11" "11" "16" "14"
Are you looking for format
?
format(as.Date(df$x,format="%Y-%m-%d"), format = "%d")
# [1] "24" "24" "11" "11" "16" "14"
If your dates are always in the same position and format, you have another option with substr()
. The call below starts with the 9th position -- the start of the day -- and ends with the 10th -- the second number of the day.
substr(x = df$x, start = 9, stop = 10)
[1] "24" "24" "11" "11" "16" "14"