loops

Insert i th vector number into data frame column name - R

不羁岁月 提交于 2020-01-21 17:19:19
问题 This is likely a quick fix! I am trying to place the ith position of my vector into my data frame column name. I am trying to use paste0 to enter the ith number. sma <- 2:20 > sma [1] 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 # Place i number from sma vector to data frame column name spx.sma <- df$close.sma.paste0("n", sma[i]) Column name should read: "close.sma.n2" If I print paste0("n", sma[i]) I obtain: > paste0("n", sma[i]) [1] "n2" So really if i paste this into my data frame

Linux Command Line using for loop and formatting results

风流意气都作罢 提交于 2020-01-21 15:42:56
问题 How can I use one command line to provide a list of all files between a certain size and then format the file with name, md5 has and the file size. The example output should be file1.*** MD5 value size file2.*** MD5 value size etc. Ive tried the following but it displays the md5 on a separate line find 'directory' -size +30000c -size -50000c | while read filename do ls -l "$filename" | awk '{print $9 "\t" $5}' md5sum "$filename" | awk '{print $1}' done It outputs the follow with the MD5 on a

Linux Command Line using for loop and formatting results

走远了吗. 提交于 2020-01-21 15:41:33
问题 How can I use one command line to provide a list of all files between a certain size and then format the file with name, md5 has and the file size. The example output should be file1.*** MD5 value size file2.*** MD5 value size etc. Ive tried the following but it displays the md5 on a separate line find 'directory' -size +30000c -size -50000c | while read filename do ls -l "$filename" | awk '{print $9 "\t" $5}' md5sum "$filename" | awk '{print $1}' done It outputs the follow with the MD5 on a

PHP array_push() is overwriting existing array elements

谁都会走 提交于 2020-01-21 14:46:09
问题 I'm trying to push objects into an array to end up with an object array like this: [ {"recipient_name":"John D", "phone_number":"123456"}, {"recipient_name":"Doe J", "phone_number":"654321"}, {"recipient_name":"Jon Do", "phone_number":"112233"}, ] So I'm looping over a larger array to acquire the names and phone numbers and pushing them as an object to an array like this: $myLargerArray = pg_fetch_all($messageQuery); // This is my larger array $size = count($myLargerArray); for( $j = 0; $j <

Java - Difference between for loop terminating expression

痴心易碎 提交于 2020-01-21 11:27:46
问题 I'm just curious: Is there a difference on speed and performance between this two loops implementation? Assume that size() method returns the length of the array,collection, or object that handles a group of elements (actually it's from XOM api). Implementation 1: int size = someArray.size(); for (int i = 0; i < size; i++) { // do stuff here } Implementation 2: for (int i = 0; i < someArray.size(); i++) { // do stuff here } 回答1: From a performance point of view, there is little difference.

CasperJS/PhantomJS .then in do/while Loop Doesn't Work

允我心安 提交于 2020-01-21 09:43:05
问题 Something like this seemed pretty logical to me but caused phantom to wtfcrash (That's what it's called in the log but doesn't give helpful info)... do { casper.then(function() { var targetFound = false; links = this.evaluate(getLinks); var searchResultsAr = []; for (var link in links) { searchResultsAr.push(links[link].replace('/url?q=', '').split('&sa=U')[0]); } for (var result in searchResultsAr) { if (searchResultsAr[result] == target) { targetFound = true; casper.echo(targetFound); break

How to display grouped data in separate tables with a PHP loop?

泪湿孤枕 提交于 2020-01-21 09:10:45
问题 I am new to phpmysqli. Here is what I have and what am trying to achieve: I will update this based on the recommendations; Database sample data I want to display the data on one page with separate tables for each student based on their sid. This is what I have tried so far; <?php include_once 'dbcon.php'; $results = $MySQLiconn->query('SELECT * FROM activitybook'); $students = []; foreach ( $results->fetch_array() as $activity ) { $students[$activity['sid']][] = $activity; } foreach($students

How to display grouped data in separate tables with a PHP loop?

感情迁移 提交于 2020-01-21 09:10:07
问题 I am new to phpmysqli. Here is what I have and what am trying to achieve: I will update this based on the recommendations; Database sample data I want to display the data on one page with separate tables for each student based on their sid. This is what I have tried so far; <?php include_once 'dbcon.php'; $results = $MySQLiconn->query('SELECT * FROM activitybook'); $students = []; foreach ( $results->fetch_array() as $activity ) { $students[$activity['sid']][] = $activity; } foreach($students

Out of memory error when reading a large file

不羁的心 提交于 2020-01-21 06:57:24
问题 I have a large csv that I want to parse and insert into my database. I have this PHP: $target = '../uploads/'.$f; $handle = fopen($target, "r"); $data = fgetcsv($handle, 0, ","); $rows = array(); while ($data !== FALSE) { $rows[] = $data; } fclose($handle); if (count($rows)) { foreach ($rows as $key => $value) { echo $value; } } Every time I try to run my script I get this error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) Any ideas how to do

Out of memory error when reading a large file

房东的猫 提交于 2020-01-21 06:56:37
问题 I have a large csv that I want to parse and insert into my database. I have this PHP: $target = '../uploads/'.$f; $handle = fopen($target, "r"); $data = fgetcsv($handle, 0, ","); $rows = array(); while ($data !== FALSE) { $rows[] = $data; } fclose($handle); if (count($rows)) { foreach ($rows as $key => $value) { echo $value; } } Every time I try to run my script I get this error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) Any ideas how to do