I have a large table, called RobertsHemp2019_20, that looks something like this:
'FileName' | 'CBDV-a' | 'CBDV' | 'CBD-a' |
---|---|---|---|
Roberts | NA | NA | NA |
NA | 413847 | NA | NA |
NA | NA | 208320 | NA |
NA | NA | NA | 118807 |
and I want to collapse the rows and remove the NA's so that it will look like this:
'FileName' | 'CBDV-a' | 'CBDV' | 'CBD-a' |
---|---|---|---|
Roberts | 413347 | 208320 | 118807 |
Each row has just one character string or value. I think I want to apply a function to each of the columns to remove the NA's (as was tried here https://stackoverflow.com/a/47357833/15779611). But I am new to R and can't get passed the collapse_column <- function(RobertsHemp2019_20,col){RobertsHemp2019_20[!is.na(RobertsHemp2019_20[,col]),col]}
command.