I am trying to use rowSds()
to calculate each rows standard deviation so that I can pick the rows that have high sds to graph.
My data frame is called
Also works, based on this answer
set.seed(007)
X <- data.frame(matrix(sample(c(10:20, NA), 100, replace=TRUE), ncol=10))
vars_to_sum = grep("X", names(X), value=T)
X %>%
group_by(row_number()) %>%
do(data.frame(.,
SD = sd(unlist(.[vars_to_sum]), na.rm=T)))
...which appends a couple of row number columns, so probably better to explicitly add your row IDs for grouping.
X %>%
mutate(ID = row_number()) %>%
group_by(ID) %>%
do(data.frame(., SD = sd(unlist(.[vars_to_sum]), na.rm=T)))
This syntax also has the feature of being able to specify which columns you want to use.