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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:04:18+00:00 2026-05-30T14:04:18+00:00

I want to do the same thing as in the R example found here:

  • 0

I want to do the same thing as in the R example found here: http://www.r-tutor.com/r-introduction/data-frame/data-frame-column-slice. He makes use of the mtcars datase which looks like this:

               mpg cyl disp  hp drat   wt ... 
Mazda RX4     21.0   6  160 110 3.90 2.62 ... 
Mazda RX4 Wag 21.0   6  160 110 3.90 2.88 ... 
Datsun 710    22.8   4  108  93 3.85 2.32 ...

And then selects the mpg and hp column with an index vector

> mtcars[c("mpg", "hp")] 
                   mpg  hp 
Mazda RX4         21.0 110 
Mazda RX4 Wag     21.0 110 
Datsun 710        22.8  93 

It’s simple to retrieve one row in rpy2, to get mpg in this case:

import rpy2.robjects as R
R.r['mtcars'][0]

However, I don’t know how to select two columns

import rpy2.robjects as R
R.r['mtcars'][R.vectors.IntVector([0,3])]

Gives

TypeError: 'IntVector' object cannot be interpreted as an index

Just like every other vector that is in R.vectors (I tried them all)

So my question comes down to, how can I get an index vector in rpy2, or if that doesn’t exist, how can I select two columns?

Thanks!

  • 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-30T14:04:20+00:00Added an answer on May 30, 2026 at 2:04 pm

    Answered on the rpy mailing list. Use the rx/rx2 to extract element the R-way (note that indexing starts at one in R).

    import rpy2.robjects as R
    R.r['mtcars'].rx[R.vectors.IntVector([0,3]).ro + 1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Albaharis PredicateBuilder as found here http://www.albahari.com/nutshell/predicatebuilder.aspx to filter results in
I want to rewrite from http://example.com/blah/<something>/<somethingelse> to http://<something>.example.com/<somethingelse> , but only if the request
I have a site whose URLs look like http://www.example.com/NY-2010/ http://www.example.com/NY-2010/location/ http://www.example.com/NY-2010/something-else/ http://www.example.com/Washington-2009/ http://www.example.com/Washington-2009/location/ http://www.example.com/Washington-2009/something-else/
I am using the bindable FlowDocument items control found here: http://msdn.microsoft.com/en-us/magazine/dd569761.aspx It works perfectly
In a nutshell: I want to do the same thing Dependency Walker does. Is
I want these two print functions to do the same thing: unsigned int Arraye[]
Basically, I want to achieve the same thing as ON DUPLICATE KEY in MySQL.
For my C# RichTextBox, I want to programmatically do the same thing as clicking
I have this Java code, and I want to do the same thing in
I found the following code on here that I think does what I want,

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.