I have two data frames:
Harry <- c(1, NA, NA, NA)
Tom <- c(NA, 2, NA, NA)
Sally <- c(NA, NA, 3, NA)
Jane <- c(NA, NA, NA, 4)
df <- data.frame(Harry, Tom, Sally, Jane)
Harry <- c(1, NA, NA, NA)
Tom <- c(1, NA, NA, NA)
Mary <- c(NA, NA, 3, NA)
Sarah <- c(NA, NA, NA, 4)
df2 <- data.frame(Harry, Tom, Mary, Sarah)
... where there's only one value per column. I'd like to flatten the data frames into single rows and then vertically concatenate such that each data frame becomes an observation in the new frame. There may be different columns, in which case these columns would be added and hence why I can't use rbind.
In addition and since these are numeric, the NAs should be zeroes and the resulting frame would look as below:
Harry <- c(1, 1)
Tom <- c(2, 1)
Sally <- c(3, 0)
Jane <- c(4, 0)
Mary <- c(0, 3)
Sarah <- c(0, 4)
df <- data.frame(Harry, Tom, Sally, Jane, Mary, Sarah)
I realise I could make everything numeric and total to get each row, but my issue is to get this into a single object.