Skip to content
Prev 385720 / 398503 Next

Is there a simple way to analyse all the data using dplyr?

Hi,
I am not sure if the request is about a 'simple way' or requires
dplyr. Here's an approach without using dplyr that is just 2 lines
(not counting creating the data or outputting the result).

n <- 500
myDf <- data.frame( gender=sample(c("Man","Woman","Other"), n, replace = TRUE),
                    GPC_score=rnorm(n), scaleMeasures=runif(n))
aL   <- list(Man="Man",Woman="Woman",All=c("Man","Woman","Other"))
z    <- sapply( 1:length(aL), function(i) { x=myDf[ myDf$gender %in%
aL[[i]], ]; cor(x[,2],x[,3]) } )
names(z) <- names(aL)
z

HTH,
Eric
On Mon, Sep 21, 2020 at 3:13 PM Chris Evans <chrishold at psyctc.org> wrote: