My dataframe
a1 <- c("a","a","b","b","c","d","e","e")
b2 <- c("01.01.2015", "02.02.2015", "14.02.2012", "16.08.2008", "17.06.2003", "31.01.2015", "07.01.2022", "09.05.2001")
c3 <- c("1a", "2b", "3c", "4d", "5e", "6f", "7g", "8h")
d3 <- c(1:8)
df2 <- data.frame(a1,b2,c3,d3, stringsAsFactors = F)
My code.
library(dplyr)
library(magrittr)
test <- df2 %>%
group_by(a1) %>%
as.Date(b2, format = "%d.%m.%Y")
Error in as.Date.default(., b2, format = "%d.%m.%Y") :
do not know how to convert '.' to class “Date”
Well, I tried without the pipe:
df$b2 <- as.Date(df$b2, format = "%d.%m.%Y")
Error in df$b2 : object of type 'closure' is not subsettable
First: Why do I get two different error messages since I am (for my understanding) am doing the same?
Second, why cant I convert my column to date?!
I might should add that I am aware of using mutate
to alter the column as date
format. But I wonder why my approach is not working.
See Question&Answers more detail:
os