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 6654871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:26:35+00:00 2026-05-26T01:26:35+00:00

I am running a cor.test on two columns within a file/table. tmp <- read.table(files_to_test[i],

  • 0

I am running a cor.test on two columns within a file/table.

tmp <- read.table(files_to_test[i], header=TRUE, sep="\t")
## Obtain Columns To Compare ##
colA <-tmp[compareA]
colB <-tmp[compareB]
# sctr = 'spearman cor.test result'
sctr <- cor.test(colA, colB, alternative="two.sided", method="spearman")

But I am getting this confounding error…

Error in cor.test.default(colA, colB, alternative = "two.sided", method = "spearman") : 
'x' must be a numeric vector

the values in the columns ARE numbers but

is.numeric(colA) = FALSE 
class (colA) = data.frame

What have I missed?

  • 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-26T01:26:36+00:00Added an answer on May 26, 2026 at 1:26 am

    Put a comma before your selector. When you select in a data.frame object with a single indexing variable without a comma it extracts a column as a list element retaining type. Therefore, it’s still a data.frame. But, data.frame objects allow you to select using matrix style notation and then you would get a simple vector. So just change

    colA <-tmp[compareA]
    colB <-tmp[compareB]
    

    to

    colA <-tmp[,compareA]
    colB <-tmp[,compareB]
    

    I think this is more keeping with the spirit of the data.frame type than double brace ([[) selectors, which will do something similar but in the spirit of the underlying list type. They also are unrelated to individual item and row selectors. So, in code that’s doing multiple kinds of things with the data.frame the double brace selectors stand out as a bit of an odd duck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running IIS5 (yes, really). I'd like to remove the eTag http header that IIS
Running into a problem. I have a table defined to hold the values of
We have a simple Webapp running on two Tomcat instances behind Apache (a Tomcat
I've got a table with about 1 million records (running SQL Server 2008 Web).
I'm running cor() on a data.frame with all numeric values and I'm getting this
Running a rails site right now using SQLite3. About once every 500 requests or
running git instaweb in my repository opens a page that says 403 Forbidden -
Running into a problem where on certain servers we get an error that the
Running FxCop on my code, I get this warning: Microsoft.Maintainability : 'FooBar.ctor is coupled
Running OS X Leopard an MacBook Pro from Jan. 2008. I used to run

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.