KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a function that takes a Date-object and returns one. However, when I applied the function to a data.frame column using the mapply function, I ran into problems: I didn't get Date-objects back, as expected, but numbers. Any idea how I could convert those to Date-objects? Also, I would be interested in what's happening here. Help is really appreciated! Minimal example: #Define simple function that takes a date-object and returns a date-object add_day <- function(dat) {return(dat + 1)} #Set up data.frame with two date-object entries in one column df <- data.frame(Col_A = c(as.Date("01/01/00", "%m/%d/%y"), as.Date("05/02/11", "%m/%d/%y"))) #That is the desired result: give a date-object to the function, get one back add_day(df[1, "Col_A"]) #Returns [1] "2000-01-02" add_day(df[2, "Col_A"]) #Returns [1] "2011-05-03" #Why does it not work here? What do I get back? mapply(add_day, df[, "Col_A"]) #Returns [1] 10958 15097; Why? What is that?
Tags (comma-separated)
Save Edits
Cancel