Creating a new column using mutate which is some function of the contents of a specified set of columns for each row in a data frame.
This seems like it should be a simple task but I've been struggling to find the right syntax something like:
df <- data.frame("annotations"=c("some","information","in","columns"),
"X001"=c(124,435,324,123),
"X002"=c(486,375,156,375))
df %>% mutate(median=median(select(.,starts_with("X"))))
So I get the original data frame with a new column 'median' which has the median across all columns starting with 'X' for each row. I think I might need a rowwise()
in there somewhere.
I'm trying to fit this into a larger dplyr pipeline so I'm looking for solutions within the 'tidyverse'