Hey,
I'm very new to R and currently struggling to calculate sums per row. Since there are some other columns with meta data I have to select specific columns (i.e. column 2 to 43) for the sum.
I tried this but it only gives "0" as sum for each row without any further error:
1)
SUM_df <- dplyr::mutate(df, "SUM_RQ" = rowSums(dplyr::select(df[,2:43]), na.rm = TRUE))
This code works but then I loose all meta data in the other columns which I want to keep
2)
SUM_df <- df %>%
select(2:43) %>%
mutate("SUMRQ" = rowSums(., na.rm = TRUE))
Is there any option to rewrite the first code and select the columns "inside" rowSums?
I'm sorry for this very basic question but I just can't find the error...
Your first suggestion is already perfect and there's no need to create a separate dataframe: the mutate() can add the SUM_RQ column to the existing dataframe, like this: