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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:52:58+00:00 2026-06-07T11:52:58+00:00

RandomForest has returned object, prd, which is class numeric with indices: > prd 298

  • 0

RandomForest has returned object, prd, which is class numeric with indices:

> prd
      298       252       373       117         0        16       442        74 
4397.9232 1826.1264 1787.1963 1388.8097 1075.7217  873.9856 1602.7068 1775.1237 
class(prd)
[1] "numeric"

I want to do a correlation test, which means getting obs in the same format. Currently, obs is a one-column data frame:

> obs
       e2004MeanY
298       4261
252       1821
373       1710
117       1138

How do I convert obs to the correct format? I can’t figure out how to tie the indices to the values in a numeric.

  • 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-06-07T11:53:01+00:00Added an answer on June 7, 2026 at 11:53 am

    You can subset a data frame using [ which, as the default is drop = TRUE will drop the empty dimension thus going from a 1 column data frame to a numeric vector. E.g.

    R> obs <- data.frame(e2004MeanY = c(4261,1821,1712,1138))
    R> rownames(obs) <- c(268,252,373,117)
    R> 
    R> (obs1 <- obs[, 1]) ## equiv of: obs[, 1, drop = TRUE]
    [1] 4261 1821 1712 1138
    R> class(obs1)
    [1] "numeric"
    

    If the losing of the row names is an issue then add them back as the names of the vector:

    R> names(obs1) <- rownames(obs)
    R> obs1
     268  252  373  117 
    4261 1821 1712 1138
    

    Of course, this isn’t an issue if you use a temporary object when you call cor(), for example:

    cor(prd, obs[, 1])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run a non-parallel randomForest object with no problem like this: > rf <-
After running a randomForest , I have an object RF that contains a bunch
I have a randomForest object that I want to save for later use. I've
I am using random forests in a big data problem, which has a very
I want to set different sampsize for randomForest in R. I expect to see
I'm trying to work around the randomForest package limit of 32 levels for factors.
I'm trying to use knn in R (used several packages( knnflex , class ))
I am using the randomForest package in R (R version 2.13.1, randomForest version 4.6-2)
Does anyone know what the mechanism is that the R randomForest package uses to
I'm using R's randomForest package. Is there a way for me to figure out

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.