"Empty" array\vector members c++

I have to fill an array of 1000 objects by reading data from disk. However, not every objects exits. Once I declare an array, memory will be reserved for 1000 objects. As I read them one by one, I set the memory to corresponding values. However, the...
more »

2017-09-09 20:09 (3) Answers

Efficiently create derangement of a vector in R

I'm looking into a way of efficiently creating a derangement (and conversely specific permutations) of a vector in R. As far as I've seen, there's no base function that does that and also there's not much about it here on SO. An obvious start is sam...
more »

2017-08-02 13:08 (1) Answers

Is it possible to skip NA values in "+" operator?

I want to calculate an equation in R. I don't want to use the function sum because it's returning 1 value. I want the full vector of values. x = 1:10 y = c(21:29,NA) x+y [1] 22 24 26 28 30 32 34 36 38 NA x = 1:10 y = c(21:30) x+y [1] 22 24 26 28...
more »

2017-07-25 20:07 (5) Answers

How to find multiple elements in an std::vector

I'm having issues trying to find multiple of the same element in a vector. I would like to find duplicate elements every 3 indexes. If there is a duplicate the next 2 elements go into a new vector. std::vector<std::wstring> wsBuf = {"one" , "...
more »

2017-07-11 19:07 (1) Answers

Modify complicated character vector automatically

I have a complicated character vector, whereby each element of the vector consists of numbers and letters. I want to simplify this vector, so that sequences of numbers and/or letters are put into ranges. Here is an example, how the input and output v...
more »

2017-07-06 16:07 (1) Answers

Nested rolling sum in vector

I am struggling to produce an efficient code to compute the vector result r result from an input vector v using this function. r(i) = \sum_{j=i}^{i-N} [o(i)-o(j)] * exp(o(i)-o(j)) where i loops (from N to M) over the vector v. Size of v is M&...
more »

2017-06-15 14:06 (2) Answers

Vectorize loop with repeating indices

I have a vector of indices that contains repeating values: IN <- c(1, 1, 2, 2, 3, 4, 5) I would like to uses these indices to subtract two vectors: ST <- c(0, 0, 0, 0, 0, 0, 0) SB <- c(1, 1, 1, 1, 1, 1, 1) However, I would like t...
more »

2017-06-13 23:06 (2) Answers

Searching the k nearest elements

I have a bunch (more or less 3500) of vectors with 4096 components and I need a fast method to see, given an input of another vector with the same length, which are the nearest N. I would like to use some matlab functions to do that. Is this ok for w...
more »

2017-06-13 10:06 (1) Answers

find and return a pointer to a object in a vector

New to c++, not really sure where I'm going wrong. Still wrapping my head around ptrs. I have a vector of profile objects. I want to find a particular object based on one of it's properties. Then I want to return that object. I don't want to make co...
more »

2017-06-05 05:06 (1) Answers

Pass std::vector as const float *?

My function is: void function(const float *, int sizeOfArray){...} My vector is: std::vector<float> myVector(size, val); I read in the docs you can use myVector[0] as standard c++ static arrays operations. How can I pass that vector to t...
more »

2017-06-02 12:06 (2) Answers

How to nest unboxed vectors?

This may be a pretty basic question, but I've searched around and I cannot seem to find the answer. I would like to represent a 2D list using unboxed Vectors. This is easily done with normal vectors: > import qualified Data.Vector as V > V.fr...
more »

2017-05-20 08:05 (1) Answers

How to compare 2 vectors using a for loop?

I have an "out of range" vector apparently, and need help catching the error. I want to iterate through a find function with each element in the vector, checking within another vector. for(int i=1201; i <= memoryQueue.size(); i++){ //cacheLoo...
more »

2017-05-03 09:05 (1) Answers