call a function from an array of vectors

In following code, i get an error on line 33. Why? What is the correct syntax? Surely I made some stupid mistake ... unfortunately I'm trying to better understand the vectors. #include <iostream> #include <vector> class firstClass { ...
more »

2017-04-17 17:04 (1) Answers

overloading = operator for self made vector class

I started writing my own vector class and got around to overloading the = operator. I have the code below for something like somevector = someothervector, although I'm not sure it's right, as I'm stuck on making another overload for something like so...
more »

2017-04-10 00:04 (1) Answers

Vector whose elements add up to a value in R

I'm trying to create a vector whose elements add up to a specific number. For example, let's say I want to create a vector with 4 elements, and they must add up to 20, so its elements could be 6, 6, 4, 4 or 2, 5, 7, 6, whatever. I tried to run some l...
more »

2017-04-07 18:04 (2) Answers

Find 1 preceded by 0 in a binary vector

Suppose I have a binary numeric vector composed by 1's and 0's. I want to find those 1's preceded by 0's in the numeric vector. So I want to get the positions 5, 9, 12 for the following vector: x <- c(1,1,0,0,1,1,1,0,1,0,0,1) I have tried this ...
more »

2017-04-06 09:04 (5) Answers

2D Vector pointer as member of class

I am new to c++. I am trying to make a class which consist of 2d vector pointer. I am creating an object that takes a 2D vector as an argument. I am trying to reference this 2D vector using pointer.This compiles just fine, but I get a segmentation f...
more »

2017-04-04 09:04 (1) Answers

Input validation in do-while

I'm having a problem with the input error.My input is validated but my error message "Invalid Range. Please Enter Range 0-100:" is not showing if there's invalid input. Here's an example: Please Enter Grade 1: 101 (It does not accept input) Please ...
more »

2017-04-02 07:04 (3) Answers

Input Validation for Vectors C++

I'm having a problem with the input validation of my do-while loop. My do-while loop only validates every other input Here's an example: Please Enter Grade 1: 101 (It does not accept input) Invalid Rage. Please Enter Range 0-100. Please Enter Gra...
more »

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

Finding groups of nonzero elements using R

I have the following problem and I can't find any easy solution. I would like to find groups of nonzero elements in a vector (separated by at least one zero) and to assign an id to each group (subsequent integer). For example, in vector value <- ...
more »

2017-03-31 23:03 (5) Answers

Cache locality with unique_ptr

I have a vector of custom classes (std::string just for example). The vector is large and I iterate through often, so I rely on cache locality. I also have one raw pointer which points at one of the vector elements. Now is the trick: The vector i...
more »

2017-03-29 22:03 (2) Answers

Scala Array Generics vs Vector Generics

So I have been working on a refactor in my project to convert Vector's in my code to Array's. The reason being that my application needs to be very performant, and using while-iterations on Array's is significantly faster than for comprehensions and ...
more »

2017-03-28 19:03 (2) Answers

Comparing string elements of two vector<Structs>

Follow on to my previous question here: Accessing local variables from void functions I've since been able to get the data I need, and now I am attempting to compare the string name attribute from each struct element passed to a function. Here is ...
more »

2017-03-28 02:03 (3) Answers

Sort vector of objects using TWO criteria

Let's say I have vector<People*> Population with class People { string name; string city; int id; }; and I'd like to sort first by name and then by city, for example: Anna, Alabama, 1284 Anna, New York, 8377 Daniel, Sydney, 8332...
more »

2017-03-22 01:03 (2) Answers

Get length of runs of missing values in vector

What's a clever (i.e., not a loop) way to get the length of each spell of missing values in a vector? My ideal output is a vector that is the same length, in which each missing value is replaced by the length of the spell of missing values of which i...
more »

2017-03-21 20:03 (3) Answers

Using vectors inside dataframe columns in R

I am programming a classificator in R, I have cases that can have multiple classes, so I would like to have both classes in the same row and the column somthing$classes, as a vector. What I mean, is that the column something$classes, of the something...
more »

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