Create std::vector in-place from raw data

Given a raw array of elements, how to create a std::vector that takes ownership of the raw array without reallocate & copy? For example having the raw array: int* elems = new int[33] how to create a std::vector of size 33 pointing to elems? I...
more »

2017-11-11 10:11 (5) Answers

is.atomic() vs is.vector()

I don't understand the difference between is.atomic() and is.vector(). From my understanding, is.vector() returns TRUE for homogeneous 1D data structures. I believe is.atomic() returns TRUE for logicals, doubles, integers, characters, complexes, and ...
more »

2017-11-03 08:11 (2) Answers

Xcode 9 vector images programatically

Xcode 9 now lets us store PDF vectors in an Asset Catalog, and check the Preserve Vector Data flag to retain the vector information after the compile. I know you can just set an image with UIImage imageNamed to make use of the vector. What I'd like...
more »

2017-10-29 20:10 (1) Answers

Vector iterator incomptible on loop

I have a problem with a loop to search for an Employee in my vector, using auto, for some reason im getting vector iterator incomptible, here is the function: Employee * searchEmp(int id,Company * comp) { for(auto i = comp->getEmployees().beg...
more »

2017-10-24 15:10 (2) Answers

gives me errors that begin and end not declared

I am trying to see if all the elements in isTableNames[] are in the array columnTableNames[] but I keep getting these errors. transform.cpp: In function 'bool is_CorrectTables()': transform.cpp:25:35: error: 'begin' was not declared in this sc...
more »

2017-10-24 01:10 (0) Answers

vector into block matrix

I have a vector given and want to transform it into a certain block matrix. Consider this simple example: k <- c(1,2,3) a <- rep(apply(expand.grid(k, k), 1, prod), each=3) a [1] 1 1 1 2 2 2 3 3 3 2 2 2 4 4 4 6 6 6 3 3 3 6 6 6 9 9 9 This vect...
more »

2017-10-20 11:10 (2) Answers

R - Subsetting over a vector with another vector

Say I have a vector like vector = c('hello','world') and another two vectors like vector2 = c(2,4) vector3 = c(4,5) How could I create a fourth vector that is the subset of each element in the first vector by the other two vectors? Something li...
more »

2017-10-19 02:10 (1) Answers

how to detect 'Enter Key' in c++?

I want to detect enter pressed to break loop. If user press 2 enters in a row, loop breaks. I'm using vector to store user input. All variable's type is integer. #include <iostream> #include <vector> using namespace std; int main() { ...
more »

2017-10-11 16:10 (1) Answers

Find line by one word in vector

Trying to find a line by one word in a vector. For example: In a file some data,like: ctrl+a move,find ctrl+c copy,group ctrl+z take,give all letters are small. Then I tried to read a file in vector - it's okay Then the user want ...
more »

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

Sort List of Vector3's by specific values

I have a list of Vector 3's and what I want to do is find the Vector3 with the highest X value, if there are multiple Vector3's with the highest X I want to have the Vector 3 with the lowest Y and highest X. I want the method to return the Z of that ...
more »

2017-09-24 14:09 (2) Answers

Default name concatenation

If I have a named vector v <- c(a = 1, b = 2) And I add them s <- v[2] + v[1] The result is a vector of length one with its element named as the first element in the arithmetic, here "b". You can remove this behavior with double brackets...
more »

2017-09-18 15:09 (0) Answers

Convert named vector to list in R

Suppose I have the following named numeric vector: a <- 1:8 names(a) <- rep(c('I', 'II'), each = 4) How can I convert this vector to a list of length 2 (shown below)? a.list # $I # [1] 1 2 3 4 # $II # [1] 5 6 7 8 Note that as.list(a) is n...
more »

2017-09-16 10:09 (3) Answers

"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