which

Getting column name which holds a max value within a row of a matrix holding a separate max value within an array

混江龙づ霸主 提交于 2019-12-04 18:30:38
问题 For instance given: dim1 <- c("P","PO","C","T") dim2 <- c("LL","RR","R","Y") dim3 <- c("Jerry1", "Jerry2", "Jerry3") Q <- array(1:48, c(4, 4, 3), dimnames = list(dim1, dim2, dim3)) I want to reference within this array, the matrix that has the max dim3 value at the (3rd row, 4th column) location. Upon identifying that matrix, I want to return the column name which has the maximum value within the matrix's (3rd Row, 1st Column) to (3rd Row, 3rd Column) range. So what I'd hope to happen is that

which(vector1 < vector2)

杀马特。学长 韩版系。学妹 提交于 2019-12-04 15:05:55
问题 Let's make a small example first, that computes in R: x<- c(1,3,1,4,2) max(which(x<2)) [1] 3 Now, I would like to do this not just for one value 2, but for many values simultaneously. It should give me something like that: max(which(x<c(1,2,3,4,5,6))) [1] NA 3 5 5 5 5 Of course I could run a for loop, but that is very slow: for(i in c(1,2,3,4,5,6)){ test[i]<-max(which(x<i)) } Is there a fast way to do this? 回答1: Find the max index of each value seen in x : xvals <- unique(x) xmaxindx <-

How to write OR condition inside which in R

主宰稳场 提交于 2019-12-04 05:55:14
问题 I am unable to figure out how can i write or condition inside which in R. This statemnet does not work. which(value>100 | value<=200) I know it very basic thing but i am unable to find the right solution. Thanks 回答1: Every value is either larger than 100 or smaller-or-equal to 200. Maybe you need other numbers or & instead of | ? Otherwise, there is no problem with that statement, the syntax is correct: > value <- c(110, 2, 3, 4, 120) > which(value>100 | value<=200) [1] 1 2 3 4 5 > which

Closest date in a vector to a given date [duplicate]

假如想象 提交于 2019-12-03 15:58:01
问题 This question already has answers here : return index from a vector of the value closest to a given element (3 answers) Closed 2 years ago . I would like to identify the closest date in a vector of given date. Let's say I have the following date vector (with 5 random dates): coldate= as.Date(c("2013-08-03", "2013-09-04", "2013-09-08", "2013-09-12", "2013-11-01")); Now, I want to find the closest date to x = as.Date("2013-10-01") inside this vector. Here is my code : > which((coldate-x) == min

which(vector1 < vector2)

谁都会走 提交于 2019-12-03 09:24:36
Let's make a small example first, that computes in R: x<- c(1,3,1,4,2) max(which(x<2)) [1] 3 Now, I would like to do this not just for one value 2, but for many values simultaneously. It should give me something like that: max(which(x<c(1,2,3,4,5,6))) [1] NA 3 5 5 5 5 Of course I could run a for loop, but that is very slow: for(i in c(1,2,3,4,5,6)){ test[i]<-max(which(x<i)) } Is there a fast way to do this? Find the max index of each value seen in x : xvals <- unique(x) xmaxindx <- length(x) - match(xvals,rev(x)) + 1L Rearrange xvals <- xvals[order(xmaxindx,decreasing=TRUE)] xmaxindx <-

How can I find a file/directory that could be anywhere on linux command line?

眉间皱痕 提交于 2019-12-03 07:22:24
问题 Ideally, I would be able to use a program like find [file or directory name] to report the paths with matching filenames/directories. Unfortunately this seems to only check the current directory, not the entire folder. I've also tried locate and which, but none find the file, even though I know its on the computer somewhere. 回答1: "Unfortunately this seems to only check the current directory, not the entire folder". Presumably you mean it doesn't look in subdirectories. To fix this, use find

'which' vs 'command -v' in Bash [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-02 20:41:47
This question already has an answer here: How to check if a program exists from a Bash script? 35 answers I've read in some bash FAQ a while ago (that I don't remember), that which should be avoided and command -v preferred. Why is that so? What are the advantages, disadvantages of either one? Well... command is likely built in to your shell, and with the -v option will tell you how your shell will invoke the command specified as its option. which is an external binary, located at /usr/bin/which which steps through the $PATH environment variable and checks for the existence of a file. A reason

How can I find a file/directory that could be anywhere on linux command line?

对着背影说爱祢 提交于 2019-12-02 19:56:09
Ideally, I would be able to use a program like find [file or directory name] to report the paths with matching filenames/directories. Unfortunately this seems to only check the current directory, not the entire folder. I've also tried locate and which, but none find the file, even though I know its on the computer somewhere. "Unfortunately this seems to only check the current directory, not the entire folder". Presumably you mean it doesn't look in subdirectories. To fix this, use find -name "filename" If the file in question is not in the current working directory, you can search your entire

Deleting rows for which a column value appears fewer than a given number of times conditional on uniqueness

不问归期 提交于 2019-12-02 14:16:29
问题 I have data that looks like date player market 1-1 1 1 1-1 2 1 1-1 1 2 1-2 2 1 1-2 3 2 1-2 12 3 1-2 11 3 1-2 2 3 1-3 24 3 1-3 4 4 1-3 21 1 1-4 1 1 1-4 51 1 1-4 1 1 1-5 1 2 I want to delete all rows related to the column Market that have appear in fewer than in three unique dates. So this would delete all rows except for those in which the Market column is 1 or 2. This is a simplified version of what I am doing, so looping is out of the question. Is there a quick way to do this? There are 60

Trigger the jQuery's keypress event on an input text

倖福魔咒の 提交于 2019-12-02 13:23:04
问题 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> 回答1: The mistake you're making is what you're expecting the jQuery's trigger method to do. If