I have a data frame with three column. I want to apply a function to compare the second and third column, my function will create a new column. With an example :
vin <- c("vin1", "vin2", "vin3", "vin4")
date.fin.obs <- rep(as.Date("2014-07-04"), length(vin))
date.fin <- c(as.Date("2014-07-04"), as.Date("2013-03-21"), as.Date("2013-07-06"),
as.Date("2014-07-04"))
df <- data.frame(vin, date.fin.obs, date.fin)
CumulSurvivants <- function(x, y){
# y <- length(x)
x.num <- as.numeric(x)
y.num <- as.numeric(y)
# i <- length(x)
i <- 0
if(x.num == y.num){
return(i)
}else{
return(i+1)
}
}
CumulSurvivants(x = df$date.fin[2], y = df$date.fin.obs[4])
seems to work, but I want to compare the two column row by row, and to write the result of my function in a new column.
Thanks in advance!