I have the following data:
(Note: I'm using the current github version of dplyr within tidyverse which offerse some new experimental functions, like condense
- which I'm using below, but I think that's not relevant for my problem/question).
library(tidyverse)
library(corrr)
dat <- data.frame(grp = rep(1:4, each = 25),
Q1 = sample(c(1:5, NA), 100, replace = TRUE),
Q2 = sample(c(1:5, NA), 100, replace = TRUE),
Q3 = sample(c(1:5, NA), 100, replace = TRUE),
Q4 = sample(c(1:5, NA), 100, replace = TRUE),
Q5 = sample(c(1:5, NA), 100, replace = TRUE),
Q6 = sample(c(1:5, NA), 100, replace = TRUE))
I now want to calculate the correlation between Q1 to Q6 within each group, and I'm using:
cor_dat <- dat %>%
group_by(grp) %>%
condense(cor = correlate(cur_data()))
Which gives me the correlations as a list-column (?). Within each list, the first column is called rowname
and I want to simply delete this column from each list in a tidyverse way. How can I do this?
I already tried something naive like select (-rowname)
, but this doesn't work.
purrr::map_df(colname, ~ select(.x, -rowname))
? – r2evansError in as_mapper(.f, ...) : object 'colname' not found
– deschen