Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:41:52+00:00 2026-05-28T01:41:52+00:00

How do you calculate Spearman correlation by group in R. I found the following

  • 0

How do you calculate Spearman correlation by group in R. I found the following link talking about Pearson correlation by group. But when I tried to replace the type with spearman, it does not work.

https://stats.stackexchange.com/questions/4040/r-compute-correlation-by-group

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:41:53+00:00Added an answer on May 28, 2026 at 1:41 am

    How about this for a base R solution:

    df <- data.frame(group = rep(c("G1", "G2"), each = 10),
                     var1 = rnorm(20),
                     var2 = rnorm(20))
    
    r <- by(df, df$group, FUN = function(X) cor(X$var1, X$var2, method = "spearman"))
    # df$group: G1
    # [1] 0.4060606
    # ------------------------------------------------------------ 
    # df$group: G2
    # [1] 0.1272727
    

    And then, if you want the results in the form of a data.frame:

    data.frame(group = dimnames(r)[[1]], corr = as.vector(r))
    #   group      corr
    # 1    G1 0.4060606
    # 2    G2 0.1272727
    

    EDIT: If you prefer a plyr-based solution, here is one:

    library(plyr)
    ddply(df, .(group), summarise, "corr" = cor(var1, var2, method = "spearman"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to calculate the fiscal year from this following code. But I
I'm looking for a way to calculate multivariate version of Spearman rank correlation $\rho$.
I have a dataframe and would like to calculate the correlation (with Spearman, data
I'm trying to calculate correlations in Perl. I found out how to calculate correlations
Calculate the convolution of the following signals (your answer will be in the form
can anyone help me calculate the complexity of the following? I've written a strStr
Im trying to calculate the bitrate from a video, but Im not sure if
I'd like to calculate the time my script runs, but my result from get-date
I need to calculate the Italian fiscal code (tax code) in C#. I've found
When I try to calculate the following integral in Mathematica 8, I get this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.