loops

Optimize/Vectorize Database Query with R

会有一股神秘感。 提交于 2021-01-27 19:42:14
问题 I am attempting to use R to query a large database. Due to the size of the database, I have written the query to fetch 100 rows at a time My code looks something like: library(RJDBC) library(DBI) library(tidyverse) options(java.parameters = "-Xmx8000m") drv<-JDBC("driver name", "driver path.jar") conn<- dbConnect( drv, "database info", "username", "password" ) query<-"SELECT * FROM some_table" hc<-tibble() res<-dbSendQuery(conn,query) repeat{ chunk<-dbFetch(res,100) if(nrow(chunk)==0){break}

C: Printing from char array produces erroneous characters

≯℡__Kan透↙ 提交于 2021-01-27 19:15:51
问题 Solutions for K. N. King's C Programming: A Modern Approach, 2nd Edition , Chapter 8, Programming Project 14, produces different outputs both correct and incorrect. Examples shown below: Reversal of sentence: you can't swallow a cage can you? Reversal of sentence: you can't swallow a cage can you�(�? Reversal of sentence: you can't swallow a cage can you��x�? Reversal of sentence: you can't swallow a cage can you�Ց�? As shown by the example input, correct output should be: Enter a sentence:

Powershell/PowerCLI Loop, timeouts and exits

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-27 19:01:29
问题 Here is the scenario - I'm remotely starting a VM via Powershell/PowerCLI (VMwares Powershell module) and once the VM is started I will be running a series of cmdlets against the VM. Currently I have this bit of code: Start-VM "my VM Name" -runAsync $vm = Get-VM | where { $_.name -eq "my VM Name" } start-sleep -seconds 20 do { start-sleep -seconds 5 $toolsStatus = ($VM | Get-View).Guest.ToolsStatus } until ($toolsStatus -eq 'toolsOK') Which works - the VM starts and the loop will check until

Iterate over different dataframe

半腔热情 提交于 2021-01-27 18:37:48
问题 I am trying to iterate over three data frames to find the difference between them. I have a master data frame which contains everything and two other data frames which contains partial of master data frame. I am trying to write a python code to identify what is missing in the other two files. Master file looks like following: ID Name 1 Mike 2 Dani 3 Scott 4 Josh 5 Nate 6 Sandy second data frame looks like following: ID Name 1 Mike 2 Dani 3 Scott 6 Sandy Third data frame looks like following:

How to count a dynamic HTML form input array with PHP?

放肆的年华 提交于 2021-01-27 17:31:27
问题 I have a button on a page that when a user pushes it, it creates another "Contact" field on the page. The Contact field allows them to add a new contact to their profile. Also, they can click the button as many times as they want, and it will create that many "Contact" fields. The problem though is that I am having a hard time figuring how many "Contact" fileds have been added. Here is some HTML that is generated when the button is clicked: <div class="item"> <label for="in-1v">First Name

How can I loop over pages and get data from every page with selenium?

a 夏天 提交于 2021-01-27 14:32:15
问题 I want to do a google search and collect the links to all hits so that I can click those links and extract data from them after collecting all links. How can I get the link from every hit? I've tried several solutions like using a for loop and a while True statement. I'll show some examples of the code below. I either get no data at all or I get only data (links) from 1 webpage. Can someone please help me figure out how to iterate over every page of the google search and get all the links so

Restart a loop in Fortran

落花浮王杯 提交于 2021-01-27 13:42:55
问题 I have an algorithm that looks like this: 10 WRITE (*,*) "Start" DO I = 1, 10 WRITE (*,*) "Step" IF(I .EQ. 5) then go to 10 END IF END DO I want to restart the loop, when that if statement executes. However, I don't want to have to use a go to, I tried this: 10 WRITE (*,*) "Start" DO I = 1, 10 WRITE (*,*) "Step" IF(I .EQ. 5) then I = 0; CYCLE END IF END DO But then I get the error that I can't redefine the I variable, inside a loop. So I'm not sure how to approach this. Any help would be much

Erase in a loop with a condition in C++

狂风中的少年 提交于 2021-01-27 12:46:32
问题 Is there a better way to write: for (auto i = container.begin(); i != container.end();) { if (condition(i)) { i = container.erase(i); continue; } ++i; } This code does what I want, but it feels like bad style. How can I improve it? My container is std::map , but a generic solution would be cool. 回答1: Use erase + remove_if : auto pred = /* lambda or something*/ container.erase(std::remove_if(container.begin(), container.end(), pred) 回答2: Is there a better way to...? It is always subjective,

How to concatenate files that have the same beginning of a name?

旧时模样 提交于 2021-01-27 10:46:00
问题 I have a directory with a few hundred *.fasta files, such as: Bonobo_sp._str01_ABC784267_CDE789456.fasta Homo_sapiens_cc21_ABC897867_CDE456789.fasta Homo_sapiens_cc21_ABC893673_CDE753672.fasta Gorilla_gorilla_ghjk6789_ABC736522_CDE789456.fasta Gorilla_gorilla_ghjk6789_ABC627190_CDE891345.fasta Gorilla_gorilla_ghjk6789_ABC117190_CDE661345.fasta etc. I want to concatenate files that belong to the same species, so in this case Homo_sapiens_cc21 and Gorilla_gorilla_ghjk6789. Almost every species

How to concatenate files that have the same beginning of a name?

别说谁变了你拦得住时间么 提交于 2021-01-27 10:43:22
问题 I have a directory with a few hundred *.fasta files, such as: Bonobo_sp._str01_ABC784267_CDE789456.fasta Homo_sapiens_cc21_ABC897867_CDE456789.fasta Homo_sapiens_cc21_ABC893673_CDE753672.fasta Gorilla_gorilla_ghjk6789_ABC736522_CDE789456.fasta Gorilla_gorilla_ghjk6789_ABC627190_CDE891345.fasta Gorilla_gorilla_ghjk6789_ABC117190_CDE661345.fasta etc. I want to concatenate files that belong to the same species, so in this case Homo_sapiens_cc21 and Gorilla_gorilla_ghjk6789. Almost every species