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

Sort vector of pairs: No matching function

I have followed the solution given here to sort a vector of pairs. And I get linear_problem.h:275: error: no matching function for call to ‘sort(std::vector<std::pair<int, double> >::iterator, std::vector<std::pair<int, double...
more »

2017-09-13 10:09 (2) Answers

Apply function to all pairs efficiently

I need a second order function pairApply that applies a binary function f to all unique pairs of a list-like structure and then combines them somehow. An example / sketch: pairApply (+) f [a, b, c] = f a b + f a c + f b c Some research leads me to...
more »

2017-09-11 12:09 (2) Answers

C++ can't push class objects into std::vector

I thought i would be used to the usage of a vector. But somehow im getting problems while pushing class Objects into my std::vector. My vector is declared in my Class : Galaxy: //Galaxy.h #ifndef GALAXIS_H #define GALAXIS_H #include "Stern.h" #inc...
more »

2017-08-28 12:08 (0) Answers

When does `modify` copy the vector?

From Apply a destructive operation to a vector. The operation will be performed in place if it is safe to do so and will modify a copy of the vector otherwise. T...
more »

2017-08-23 14:08 (1) Answers

Creating class object in the game loop

I'm wondering how is the proper way to create objects of classes in the game loop once? For example I've Box, Sphere, Cyllinder classes and I want to create several objects at different time while the program is running and work with them in the futu...
more »

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

C++ vector storing generic T type classes

I have a Foo class that expects T type values. I'd also like to store them in a vector. I've tried several methodologies, but didn't find any solutions. Please have a look at the source code below to get the idea what I'd like to achieve. #include &...
more »

2017-08-14 15:08 (1) Answers

Run function on vector without sapply

I would like to understand how I can write a function to execute a certain rule on the elements of a vector. Assume I want to multiply by a value all the elements of a vector, the below code returns: a<-c(1, 3, 5, 7, 10) f <-function(x){ f<...
more »

2017-08-14 12:08 (2) Answers

Name the header from a file

this is the script I'm on: data <- read.table(file.choose(), header = FALSE, sep = "") data.header <- read.table(file.choose(), header = FALSE, sep = "") data.names <- as.vector(data.header[1,]) names(data) <- data.names Basically, my...
more »

2017-08-11 23:08 (1) Answers

Haskell Pattern Match Vectors

I'm following an online tutorial on Haskell. We define a function to add two-dimensional vectors, represented by tuple pairs of numbers. The following is the explicit type declaration, that ensures both inputs are two-dimensional vectors. addVectors...
more »

2017-08-11 01:08 (1) Answers

C++ Vector of Monsters

I want to make a vector where the type is my overloading constructor or to be precise I want to make a vector of monsters but I cant seem to pass it and I have no idea why. What did I do wrong? // Monster.cpp #include <iostream> #include <...
more »

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