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

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

## Having a function output two quantities in looping structure in R?

In my R function below, I'm wondering how I can change my code such that I can get pe out of my fun function? Right now, fun only outputs L and U. P.S. Of course, I want to keep the function work as it does right now, so therefore replicate may also...
more »

## How does index*int in a for loop end up with zero as result?

We tried just for fun to create a for loop like below. We assumed that the number we get would be very high but we got 0. Why is it 0 and not something big? We even tried it with a long because we thought it might be bigger than a int. Thanks in adv...
more »

## How does NumPy multidimensional array iteration work? (With and without nditer)

Note: I am not sure if this is a duplicate or not -- please let me know if it is (and close the question). If one has a 1-dimensional NumPy array vector, then if one writes a for loop of the form: for element in vector : print(element) The re...
more »

## Validate a field's value if greater than another field's value in jQuery

I am a begginer in jQuery could you help me build a script for this? I have set's of fieldset which have set of input <p><input type="radio" class="scenarioRadio" value="5" name="group26" /><label>Strongly agree </label><...
more »

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

## write a for loop to automatically create subsets of datasets in r

Please help me as I am new to R and also programming I am trying to write a loop in such that it should read the data for every 1000 rows and create a data-set in r Following is my trial for(i in 0:nl){ df[i] = fread('RM.csv',skip = 1000*i, nro...
more »

## Why does my for loop return the correct answer, but my forEach does not?

this is my first question on SO. I have an assignment where I'm supposed to create a function that has two parameters--the first being an array of strings, and the second being a string to possibly match in the array. I have two variations of the f...
more »

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

## Call a function with the variables of a for statement

I trying to use a try statement in Python to check in 4 variables are numbers, if a variable contains something other than a number I have got it to ask the user to input try again, but then I want to have it call a function with those 4 variables (w...
more »

## Assign a binary vector based on blocks of data within another vector

I have a data frame: dat <- data.frame(diffsecs=(c(189, 245, 13988, 2396, 29601, 263, 297, 292, 230, 257, 192, 286, 236, 261, 286, 268, 294, 260, 286, 299, 514, 2287, 234, 195, 250, 519, 560, 3314, 12340, 186, 184, 180, 180, 180, 18...
more »

## Reorganise array, move indexes to specific locations php

I have an arbitrary number of arrays all containing the same format of data. There are 2 separate for loops looping through two separate SQL query results and adding them to 2 separate arrays. Once I have all the information in both arrays, I am wal...
more »

## Is there any dynamic code for for-loop or any other loop for works on big data?

Data.csv file(sample data) Taluka Crop Village Area T1 C1 V1 11 T1 C1 V2 15 T1 C1 V3 3 T1 C1 V4 1 T1 C1 V5 2 T1 C2 V1 12 T1 C2 V2 16 T1 C2 V3 4 T1 C2 V4 100 T1 C2 V5 52 T1 C3 V1 47 T1 C3 V2 15 T1 C3 V3 21 T...
more »

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

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

## VBA Excel: Non-Active Sheet and Unknown Number of Rows. If cell contains value, perfom calculation and insert new value into cell on same row

I have tried my best to search for the answer but can't get what I'm looking for. I'm very new to VBA so may be going wrong in several places here . . . I'm creating a data formatter that processes data with a different numbers of records (rows) eac...
more »

## For loop entire DOM created code, so correct divs will be looped

I tried to create an array and loop this code that creates three images that once clicked present a UL with li type checkbox. trouble is, as you can see on Fiddle, it created the images but also looped many other irrational things. and for some reas...
more »

## For loop to send emails with VBA: Only first email sends

Sorry if this is close to a duplicate question or not formatted correctly, this is a first-time for me. In VBA, I am trying to loop through my spreadsheet and send emails when a cell value is equal to 1. This code works to send the first email(or oc...
more »

## How to speed up nested for loops with function call in python 3?

I have been trying to make 3D drawing library for python 3, using Pygame. I want to use Z-Buffer so I need to call function for each pixel that should be drawn. Problem is that drawing 100x100 pixel rectangle takes more than 1 millisecond. Drawing f...
more »

## Simplify numpy.dot 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 + np.dot(a, s)) data sho...
more »

## Getting one row from a nested array, push values into input then setTimeout to change to next array?

I'm a beginner and it'll show :( but could anyone assist me into the right direction? I have an object literal with arrays nested inside. I need to grab the first row of arrays then push the values of that row into the three different inputs. Then af...
more »

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

## How to get values from dynamically generated DOM input elements Java

so I have this HTML code: <form method="get" action="#" id="startForm"> <input type="text" name="period" id="period" placeholder="The number of days"/> <input type="submit" name="submit" value="submit" id="startSubmit"/> &l...
more »

## Java: Fail to declare a local variable in loop without braces

I'm perplexed about it: I can write my code in this way and it outputs "Hello World!" without errors. public class Test { public static void main(String[] args) { for (int i = 0; i <= 10; i++) { Integer k = new Integer(i); } ...
more »

## Running a for loop through 2 arrays of different lengths and index manipulation

I need to run a for loop through 2 arrays of different lengths. One array is 8760 by 1 and the other is 10 by 1. If a value in the short array is equal to to the index of a value in the long array, I don't want to change anything. If the index of a v...
more »

## Functions which have for loop dependence

Suppose I have the following: def f(t): return a*t def g(t): a=5 b=4 for u in range(t): a=a+u b=f(t)+b return b At each step, will the f(t) updating b in the 'for' loop have in its definition the...
more »

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

## BASH one-line alphabetical mass file sort using for, mv, and grep

Problem I've got thousands of files with the format "^[[:digit:]]\{4\} - [[:alpha:]].*", for exampe: 7958 - a3ykof zyimeo3.txt. I'm trying to simply move them into folders alphabetically beginning with the first alpha-character after the hyphen. I ...
more »

## VBA Excel For loop with Variant Arrays crashing Excel

Afternoon all. I'm working on adding and undetermined number of values (customers) to a variant array using a For/Next loop and ReDim Preserve. My code below: lRow = sht1.Cells(sht1.Rows.Count, 1).End(xlUp).Row cCount = 0 uCount = 0 var_Events = ...
more »

## Need help extending a function and for loop in R

I have the following function with a for loop: getSequences <- function(input.seq){ peptide.result <- c() for (i in 1:nrow(peptides.df)) { peptide.seq <- substr(input.seq, peptides.df\$StartAA[i], peptides.df\$EndAA[i]) peptide.info &...
more »

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

## How to get the entire elements in x after the for loop for plotting in R?

I was wondering how I could get the entire 5 elements of the vector x after the for-loop much like I get the 5 elements of the vector ts in my R code below: if(!require(BayesFactor)){install.packages('BayesFactor')} ; library(BayesFactor) ts = n...
more »

## How do you make a vector of strings in for loop

How do convert a int array to a str array input: x = np.array([0,1,2,3....]) len(x)=73293 output: y = np.array(["0","1","2","3"....]) We though about doing something like this: y=[] for i in range(len(x)): y=y.append(str(x[i])) but ...
more »