Iterate over pattern grep function in R

I am novice in R. I want to write the loop for the below code in R. day1<-XYZ[, -grep("_0", colnames(XYZ))] day2<-XYZ[, -grep("_0|_1", colnames(XYZ))] day3<-XYZ[, -grep("_0|_1|_2", colnames(XYZ))] day4<-XYZ[, -grep("_0|_1|_2|_3", colname...
more »

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

Solving for two parameters using `optim()` in R?

I'm trying to find shape1 and shape2 in dbeta() such that the answer from dbeta() for the two input values: .6 and .8 become 3. I'm using the below optim() but don't get exact result, that is I expect getting values for shape1 and shape2 that when u...
more »

2017-08-15 01:08 (0) Answers

for loop performance iteration

The question is, "We might expect method3 to run faster than method2, why is that?" but I have no idea. It seems like both methods do the same amount of operations. Could someone please enlighten me? ArrayList<Person> method2(Person x, Arr...
more »

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

python: Nesting a triangle within another triangle

I am trying to write code that will display a triangle with an odd width. Once the triangle is completed it is placed inside an outer triangle. The user will be able to input the characters used for the triangle and the number of rows. I am hoping to...
more »

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

for loop 4 DOM elements and their events in JS

I am trying to loop these 3 images followed by their ul and li. Once clicked I came across an issue that the event handler isn't listening on any of the images other than the first. Please help me out. Fiddle JS var main = function () { var r...
more »

2017-07-25 09:07 (1) Answers

For Loop with Subset in R

I have the following data in a csv file: Date Model Color Value Samples 6/19/2017 Gold Blue 0.5 500 6/19/2017 Gold Red 0.0 449 6/19/2017 Silver Blue 0.75 1320 6/19/2017 Silver Blue...
more »

2017-07-24 19:07 (3) Answers

Simplify within loop

Is it possible to simplify this: import numpy as np a = np.random.random_sample((40, 3)) data_base = np.random.random_sample((20, 3)) mean = np.random.random_sample((40,)) data = [] for s in data_base: data.append(mean +, s)) data sho...
more »

2017-07-18 01:07 (1) Answers

PasteSpecial (Run-time error 1004)

I want to copy the data (formulas) from one sheet of the book to another , then also in other books and their sheets . Gives an error (Run-time error 1004). And where inserted , inserts only values(without formulas) . Error in line : Selection.Paste...
more »

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

requestanimationframe drawing with for loop issue

I'm working on a tetris game - still - and am trying to use requestAnimationFrame to draw my T piece on the black board. This is the problem. the requestAnimationFrame draws the piece 2 times, then stops drawing even though the for loop is still ru...
more »

2017-06-30 20:06 (1) Answers

Triple for loop in matrix scanning

As say in the title i'm actually using a triple for loop to treat a numpy matrix called A in my python program and , as we can expect, it's very slow. I have a function that we gonna call "return_bool" which return a boolean in function of a paramete...
more »

2017-06-26 11:06 (1) Answers

Write a for loop in a function to get a matrix

I need to put delta.vec and sigma.vec values through my required.replicates function and store them in my practice1 matrix. But I get NULL. sigma.vec <- c(2,4,6,8,10,12) delta.vec <- c(1,2,5,8,10) practice1 <- matrix(0, nrow=length(delta...
more »

2017-06-17 14:06 (1) Answers