which

csh script: check if command exists

混江龙づ霸主 提交于 2019-12-02 09:15:38
问题 I would like to have something like this if (command_not_exists) exit Can someone tell me how to achieve this functionality in a cshell script? 回答1: My problem is solved using where command (I was trying with which command). Solution: if(`where test_cmd` == "") then printf "\ntest_cmd: Command not found\n"; exit(1); endif Thanks 来源: https://stackoverflow.com/questions/22040308/csh-script-check-if-command-exists

Trigger the jQuery's keypress event on an input text

孤街醉人 提交于 2019-12-02 07:00:39
Regarding the .trigger() method , the Event object , the which property , the JS char codes and the code below, why does the #example input don't get the char a as auto-written value? Did I misunderstand the .trigger() method? <input type="text" name="example" id="example" value="" /> <script> $(function() { var e = jQuery.Event("keydown", { which: 65 }); $("#example").focus().trigger(e); }); </script> The mistake you're making is what you're expecting the jQuery's trigger method to do. If you check out the code you'll see that what it is doing is actually executing the jQuery registered event

Best way to feed which(,arr.ind=T) back into matrix in R?

孤街浪徒 提交于 2019-12-01 23:12:57
问题 I have extracted the array indeces of some elements I want to look at as follows: mat = matrix(0,10,10) arrInd = which(mat ==0,arr.ind = T) Then I do some more operations on this matrix and eventually end up with a vector or rows rowInd and a vector of columns colInd . I want us these indeces to insert values into another matrix, say mat2. But I can't seem to figure out a way to do this without looping or doing the modular arithmetic calculation myself. I realize I could take something like

Cbind/Rbind With Ifelse Condition

非 Y 不嫁゛ 提交于 2019-12-01 23:09:30
问题 Here is the code that I am working with: x <- c("Yes","No","No","Yes","Maybe") y <- t(1:10) z <- t(11:20) rbind.data.frame(ifelse(x == "Yes",y,z)) This produces X1L X12L X13L X4L X15L 1 1 12 13 4 15 The desired outcome is: x 1 Yes 1 2 3 4 5 6 7 8 9 10 2 No 11 12 13 14 15 16 17 18 19 20 3 No 11 12 13 14 15 16 17 18 19 20 4 Yes 1 2 3 4 5 6 7 8 9 10 5 Maybe 11 12 13 14 15 16 17 18 19 20 I was thinking that I could use an ifelse statement with the rbind.data.frame() or cbind.data.frame() function

Unexpected behavior using -which() in R when the search term is not found

丶灬走出姿态 提交于 2019-12-01 22:57:26
问题 I have been using the R which function to remove rows from a data frame. I recently discovered that if the search term is NOT in the data.frame, the result is an empty character. # 1: returns A-Q, S-Z (as expected) LETTERS[-which(LETTERS == "R")] # 2: returns "character(0)" (not what I would expect) LETTERS[-which(LETTERS == "1")] # 3: returns A-Z (expected) LETTERS[which(LETTERS != "1")] # 4: returns A-Q, S-Z (expected) LETTERS[which(LETTERS != "R")] Is the second example the expected

Unexpected behavior using -which() in R when the search term is not found

旧时模样 提交于 2019-12-01 21:16:24
I have been using the R which function to remove rows from a data frame. I recently discovered that if the search term is NOT in the data.frame, the result is an empty character. # 1: returns A-Q, S-Z (as expected) LETTERS[-which(LETTERS == "R")] # 2: returns "character(0)" (not what I would expect) LETTERS[-which(LETTERS == "1")] # 3: returns A-Z (expected) LETTERS[which(LETTERS != "1")] # 4: returns A-Q, S-Z (expected) LETTERS[which(LETTERS != "R")] Is the second example the expected behavior for -which() when the search term is not found? I have already switched my code to use the syntax in

R function which.max with tapply

白昼怎懂夜的黑 提交于 2019-12-01 21:06:07
问题 I am trying to make a data frame with the maximum over records by a factor. I would like a data frame with 4 rows (one for each G) with the max for X in that group and the corresponding Y value. I know I could write a loop but would rather not. Data<-data.frame(X=rnorm(200), Y=rnorm(200), G=rep(c(1,2,3,4), each=50)) XMax<-tapply(Data$X, Data$G, function(x){max(x, na.rm=T)}) WhichXMax<-tapply(Data$X, Data$G, function(x){which.max(x)}) The which.max function returns the row number after the

Cbind/Rbind With Ifelse Condition

落花浮王杯 提交于 2019-12-01 20:27:16
Here is the code that I am working with: x <- c("Yes","No","No","Yes","Maybe") y <- t(1:10) z <- t(11:20) rbind.data.frame(ifelse(x == "Yes",y,z)) This produces X1L X12L X13L X4L X15L 1 1 12 13 4 15 The desired outcome is: x 1 Yes 1 2 3 4 5 6 7 8 9 10 2 No 11 12 13 14 15 16 17 18 19 20 3 No 11 12 13 14 15 16 17 18 19 20 4 Yes 1 2 3 4 5 6 7 8 9 10 5 Maybe 11 12 13 14 15 16 17 18 19 20 I was thinking that I could use an ifelse statement with the rbind.data.frame() or cbind.data.frame() function. So if x == "Yes" then that would be combined with a vector "y". As shown in the first row of the

What does ( !'which npm' ) mean in a PHP script?

岁酱吖の 提交于 2019-12-01 19:36:07
What does ( !'which npm' ) mean in the following code? if ( !'which npm' ) { die( 'You need to install NPM!' . PHP_EOL ); } Here is a link to the complete file from GITHUB: WPBP/generator/bin/wpbp-generator deceze It checks whether a hardcoded string is falsey . Which will always be false . This logic looks a bit meaningless. I suspect the author rather wanted to write: if (!`which npm`) The backtick operator executes the command as shell command, which makes a bit more sense. 来源: https://stackoverflow.com/questions/52094786/what-does-which-npm-mean-in-a-php-script

R function which.max with tapply

為{幸葍}努か 提交于 2019-12-01 19:13:05
I am trying to make a data frame with the maximum over records by a factor. I would like a data frame with 4 rows (one for each G) with the max for X in that group and the corresponding Y value. I know I could write a loop but would rather not. Data<-data.frame(X=rnorm(200), Y=rnorm(200), G=rep(c(1,2,3,4), each=50)) XMax<-tapply(Data$X, Data$G, function(x){max(x, na.rm=T)}) WhichXMax<-tapply(Data$X, Data$G, function(x){which.max(x)}) The which.max function returns the row number after the data has been subsetted by the tapply factor, where I really want the row number referencing the Data rows