I would like to create a new column called maxdate and mindate from a list of date columns assuming 4 date columns and has missing values.
The solution below only gives the max/min of the rows of the columns. I am interested in finding max/min date across the columns.
df$maxdate <- apply (df[1:4], 1, max, na.rm = TRUE)
df <- data.frame(
col1 = c("11/09/1999", "11/09/1999", "11/09/1999", "11/09/1999", "11/09/1999"),
col2 = c("01/01/2000", "01/01/2000", "01/01/2000", "01/01/2000", "01/01/2000"),
col3 = c("12/09/1961", "10/03/1995", "30/03/1992", "25/05/1992", "25/05/1992"),
col4 = c("01/01/1930", "01/01/1939", "01/01/1942", "01/01/1936", "01/01/1937")
)
sample data
col1 col2 col3 col4
11/09/1999 01/01/2000 12/09/1961 01/01/1930
11/09/1999 01/01/2000 10/03/1995 01/01/1939
11/09/1999 01/01/2000 30/03/1992 01/01/1942
11/09/1999 01/01/2000 25/05/1992 01/01/1936
11/09/1999 01/01/2000 25/05/1992 01/01/1937