## Counting the number of occurrences of a value in R

If I have a vector of numbers in R. numbers <- c(1,1, 2,2,2, 3,3, 4,4,4,4, 1) I want to return a vector that provides the number of times that value has occurred cumulatively along the vector. I.e. results <- c(1,2, 1,2,3, 1,2, 1,2,3,4, 3) ...
more »

## Count vector elements in range when condition is met

I have a vector of numbers: x <- c(0, 0, 0, 30, 60, 0, 0, 0, 0, 0, 10, 0, 0, 15, 45, 0, 0) For each element i in x, I would like to do the following If x[i] > 0, return 0 If all 4 elements before x[i] are 0, return NA If the 4 elements bef...
more »

## 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 »

## Reverse count vector elements when sequence occurs

I have a vector with values NA, 0, and 1: x <- c(NA, 0, 0, 1, 1, 1, 1, NA, 0, 0, 0, 0, NA, NA, 1, 1, 1, NA) #> x #[1] NA 0 0 1 1 1 1 NA 0 0 0 0 NA NA 1 1 1 NA Whenever the sequence switches from 1 to NA, I would like to count th...
more »

## 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 »

## for - loop for group of elements in vector that references other vector

I am trying to find out why this piece of code returns -1. The fault lies within this piece of code, and I guess I am handling the iterators wrongly here. What I am trying to do is calculate a geometric mean. You can fault me for several things here ...
more »

## 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 »

## references to other resources are not supported by build-time PNG generation

AndroidStudio 3.0 \ Android Gradle plugin 3.0 <vector <path android:fillColor="@color/image_button_disabled"/></vector> I have this error : references to other resources are not supported by build-time PNG generation It wil...
more »

## 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 »

## 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 »

## 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 »

## 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 »

## 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 »

## 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 »

## 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 »

## c++ float vector does not recognize float number?

I have following code which that initialize a float vector: std::vector<float> arr= { -11, -12, -45.3, -34.5, 110, 5, 10,3 ,22, 100, 1, 23 }; However I am get a compiling error: error C2398: Element '3': conversion from 'double' to 'float'...
more »

## What does "X += nb; Y+= nb;" mean if X and Y are two vectors and nb is an integer?

at page 8 of the paper : [Reducing floating point error in dot product using the superblock family of algorithms- Anthony M. Castaldo , R.Clint Whaley, and Anthony T. Chronopouos][1] there is the following code: typedef double scalar; typedef sca...
more »

## 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 »

## 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 »

## Element of vector to different columns of data frame

I have a df: group number id 1 A abcd 1 2 A abcd 2 3 A abcd 3 4 A efgh 4 5 A efgh 5 6 B abcd 1 7 B abcd 2 8 B abcd 3 9 B abcd 9 10 B ijkl 10 I want to make it like th...
more »

## Create sequence between certain values across two vectors

I am currently trying to create sequences between values of different vectors that do not have the same length. Imagine I have the two following vectors a and b: a<-c(1, 8, 14, 34, 46, 55) b<-c(3, 6, 12, 13, 18, 42, 49, 50, 57, 200) I would...
more »

## "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 »

## C++ Find object in vector and call a member function on it

This is homework related, so I must use a vector to store these objects. I have a base class BankAccount with derived CheckingAccount and SavingsAccount I ask the user which account they want to input data for, i.e. Checking or savings and then ask ...
more »

## Is it possible to create an atomic vector or array in C++?

I have some code which uses an array of int (int[]) in a thread which is activated every second. I use lock() from std::mutex to lock this array in this thread. However I wonder if there is a way to create an atomic array (or vector) to avoid using...
more »

## Is it allowed/common use to a getter for getting an "embedded" variable or object?

There is something that I've been wondering for a while and I hope you guys can share your thoughts on the matter. I first discovered this problem around a half a year ago when I programmed a robot that was controlled by a PLC. In structured text I u...
more »

## find not working while I am trying to create a vector containing unique elements in c++

Find not working while I am trying to create a vector containing unique elements. The string is first tokenized and then it need to be reversed. but elememts in reversed string must be unique. #include <cstring> #include <vector>...
more »

## C implementation for C++ strings & vector of strings

I've some C++ APIs like below: API1(std::string str, std::vector<std::string> vecofstr); I want to call this API from a C code. How can i provide a C wrapper for this ? std::string str => I can probably use char* for std::string &...
more »

## Perfomance Impact of Nested Vectors vs. Contiguous Arrays

Have there been any reliable tests that clearly display the performance differences between accessing and writing to nested vectors versus C++'s built-in arrays? I've heard that using nested (multi-dimensional) vectors typically have some performanc...
more »

## 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 »

## 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 »

## Extract series of successive vectors from matrix

I have a large matrix, say for simplification: > mat = matrix(c(1:50), ncol = 5) > mat [,1] [,2] [,3] [,4] [,5] [1,] 1 11 21 31 41 [2,] 2 12 22 32 42 [3,] 3 13 23 33 43 [4,] 4 14 24 34 44 ...
more »

## How to remove a particular repeating element after the first from a character vector

I have a vector of path steps and there's one particular path step that if it repeats I want to eliminate the repetitions. For example, my_vec = "A > A > X > B > X > X > X > C > C" Now if 'X' repeats, then I want to elimin...
more »

## 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 »

## How to check if my vector contains anything other than x

I have a vector of strings allowed to contain only alphabets or dash(-) or both of them. I need to check if any character other than dash or alphabets is present in my vector.. how can I do this? my general idea is to use find from algorithm and tell...
more »