I have the following data set:
Data1 Data2 Data3
3 NAN NAN
2 NAN NAN
3 NAN NAN
NAN 3 NAN
NAN 5 NAN
NAN 3 NAN
NAN NAN 7
NAN NAN 5
NAN NAN 1
I'd like to summarise it into this:
Data1 Data2 Data3
3 3 7
2 5 5
3 3 1
I've trying creating a row number, grouping by row number and applying summarise
, but it's just filling the NaNs with 0.
data = data %>%
mutate(row = row_number()) %>%
dplyr::group_by(row) %>%
dplyr::summarise(across(c("Data1","Data2","Data3"), ~sum(., na.rm=T))) %>%
distinct(.)
dput
. Do you haveNAN
as text or the value in R which isNaN
. Adding data withdput
will clarify that the way data is shown is not clear.