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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:33:59+00:00 2026-06-15T18:33:59+00:00

How can I resize in Rcpp a NumericVector ? When I use the push_back

  • 0

How can I resize in Rcpp a NumericVector?

When I use the push_back function for this, the Program slows down. But there are no .resize() or .reserve() functions.
(When I have already a NumericVector with the desired size, I can use the copy-constructor to get the correct size of the NumericVector. This is in such a case much faster than usage of push_back)

  • 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-15T18:34:01+00:00Added an answer on June 15, 2026 at 6:34 pm

    If you prefer the C++ idioms, use std::vector<double> and return that at the end where it will be converted via an implicit wrap() to an R vector. You could also use Armadillo or Eigen vectors via RcppArmadillo and RcppEigen.

    Our objects are shallow wrappers around the R object, so push_back on, say, a Rcp::NumericVector always needs a full copy. That is known and documented.

    Edit: So for completeness, here is an example using RcppArmadillo:

    // [[Rcpp::depends(RcppArmadillo)]]
    #include <RcppArmadillo.h>
    
    // [[Rcpp::export]]
    arma::vec shrink(arma::vec x) {
        arma::vec y = x;
        y.resize( y.size()-2 );
        return y;
    }
    

    which we can deploy via

    R> Rcpp::sourceCpp('/tmp/vec.cpp')
    R> shrink(1:10)
         [,1]
    [1,]    1
    [2,]    2
    [3,]    3
    [4,]    4
    [5,]    5
    [6,]    6
    [7,]    7
    [8,]    8
    R> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can i resize images in python to given height and width,i use python 2.5,
Is there a way that I can resize the window only in proportion? It
Can anyone suggest the script for Image Resize with drag? But I want the
So my website can resize based on screen size, but when I implemented a
Is there a way I can resize, crop, and center an image using html/css
hi according to the ci document you can resize images with image_lib and there
Is there anyway using CSS or JS that you can resize the input type=file
is there any jquery or another brand of plugins which can resize image inside
Does anyone know how I can resize a winform when it has no border.
I want to get each circle inside a div so i can resize it

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.