which

Which numbers are present in a vector but not in another one [duplicate]

╄→гoц情女王★ 提交于 2019-12-01 14:37:25
This question already has an answer here: How to tell what is in one vector and not another? 5 answers I guess it is a very easy question. v1 = 1:10 v2 = c(2,4,7) (none of the numbers are repeated. No need to use unique() ) I want a vector containing all the values in v1 that are not in v2. solution = c(1,3,5,6,8,9,10) I can do this using a for loop but I'm sure there are easier solution. setdiff(v1, v2) # [1] 1 3 5 6 8 9 10 Use the %in% operator with logical NOT ( ! ) to subset v1 by values not in v2 : v1[ ! v1 %in% v2 ] #[1] 1 3 5 6 8 9 10 Or you could look for non-matches of v1 in v2 (this

Which numbers are present in a vector but not in another one [duplicate]

℡╲_俬逩灬. 提交于 2019-12-01 12:34:55
问题 This question already has answers here : How to tell what is in one vector and not another? (6 answers) Closed 6 years ago . I guess it is a very easy question. v1 = 1:10 v2 = c(2,4,7) (none of the numbers are repeated. No need to use unique() ) I want a vector containing all the values in v1 that are not in v2. solution = c(1,3,5,6,8,9,10) I can do this using a for loop but I'm sure there are easier solution. 回答1: setdiff(v1, v2) # [1] 1 3 5 6 8 9 10 回答2: Use the %in% operator with logical

Is there a Perl module that works similarly to the Unix “which” command?

喜你入骨 提交于 2019-12-01 03:26:09
问题 I was on Perlmonks and found this great listing: http://www.perlmonks.org/?node_id=627015 But it was missing "which", the function that searches for an executable in all the directories in your PATH. (I am porting a Perl script to Windows.) Is there a Perl module that simulates this? 回答1: File::Which. Always check CPAN! :) 回答2: Have you seen this Snippet? which (for Windows) in pure perl The follow-up points to the module File::Which on CPAN. 来源: https://stackoverflow.com/questions/1233129/is

which命令、whereis命令、 find命令 、locate命令、文件名后缀

北城以北 提交于 2019-12-01 03:25:43
which命令 which命令只能用来查找PATH环境变量中出现的路径下的可执行文件。有时我们不知道某个命令的绝对路径时可以使用which命令来查找 [root@localhost ~]# which ls alias ls='ls --color=auto' /usr/bin/ls whereis 命令 whereis命令通过预生成的一个文件列表库查找与给出的文件名相关的文件,使用格式为:whereis 参数 文件名 其参数如下 b:只查找二进制文件 m:只查找帮助文件(在man目录下的文件) s:只查找源代码文件 whereis命令类似于模糊查找,只要文件中包含要查找的字符,都会显示出来。 [root@localhost ~]# whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz locate命令 locate命令类似于whereis,也是通过查找预生成的文件列表库来告诉用户要查找的文件在哪里,后面直接跟文件名。一般机器上没有安装这个软件包,使用yum install -y mlocate 安装。在安装完毕之后第一次使用会报错,因为系统上没有生成文件列表库,可以通过使用updatedb命令立即生成这个库,但是如果机器上正运行着重要业务最好不要运行这个命令,因为一旦执行,服务器的压力会增加。 [root@localhost

More efficient strategy for which() or match()

懵懂的女人 提交于 2019-11-30 14:38:24
I have a vector of positive and negative numbers vec<-c(seq(-100,-1), rep(0,20), seq(1,100)) the vector is larger than the example, and takes on a random set of values. I have to repetitively find the number of negative numbers in the vector... I am finding this is quite inefficient. Since I only need to find the number of negative numbers, and the vector is sorted, I only need to know the index of the first 0 or positive number (there may be no 0s in the actual random vectors). Currently I am using this code to find the length length(which(vec<0)) but this forces R to go through the entire

Speeding up function that uses which within a sapply call in R

拟墨画扇 提交于 2019-11-30 09:34:24
I have two vector e and g . I want to know for each element in e the percentage of elements in g that are smaller. One way to implement this in R is: set.seed(21) e <- rnorm(1e4) g <- rnorm(1e4) mf <- function(p,v) {100*length(which(v<=p))/length(v)} mf.out <- sapply(X=e, FUN=mf, v=g) With large e or g , this takes a lot of time to run. How can I change or adapt this code to make this run faster? Note: The mf function above is based on code from the mess function in the dismo package. The reason this is so slow is because you're calling your function length(e) times. It doesn't make a large

Pandas Equivalent of R's which()

浪子不回头ぞ 提交于 2019-11-30 08:42:01
Variations of this question have been asked before, I'm still having trouble understanding how to actually slice a python series/pandas dataframe based on conditions that I'd like to set. In R, what I'm trying to do is: df[which(df[,colnumber] > somenumberIchoose),] The which() function finds indices of row entries in a column in the dataframe which are greater than somenumberIchoose, and returns this as a vector. Then, I slice the dataframe by using these row indices to indicate which rows of the dataframe I would like to look at in the new form. Is there an equivalent way to do this in

Finding the column number of the smallest element in a certain row

有些话、适合烂在心里 提交于 2019-11-29 16:30:54
Using R Say for example you have a matrix such as the one below. > C<-matrix(c(0,-7,2,8,0,0,3,7,0,3,0,3,0,0,0,0),nrow=4,byrow=TRUE) > C [,1] [,2] [,3] [,4] [1,] 0 -7 2 8 [2,] 0 0 3 7 [3,] 0 3 0 3 [4,] 0 0 0 0 How do you find the column number of the smallest element in a certain row. For example I want to know what column number the smallest element in row 1 is. Therefore the output should just be 2. As the smallest element in row 1 is -7 and that is in column 2. I'm assuming the answer is very easy but i just can't seem to do it! I tried doing the following but it just gives me the answer of

Speeding up function that uses which within a sapply call in R

醉酒当歌 提交于 2019-11-29 14:35:04
问题 I have two vector e and g . I want to know for each element in e the percentage of elements in g that are smaller. One way to implement this in R is: set.seed(21) e <- rnorm(1e4) g <- rnorm(1e4) mf <- function(p,v) {100*length(which(v<=p))/length(v)} mf.out <- sapply(X=e, FUN=mf, v=g) With large e or g , this takes a lot of time to run. How can I change or adapt this code to make this run faster? Note: The mf function above is based on code from the mess function in the dismo package. 回答1:

Why jQuery's event.which gives different results in Firefox and Chrome?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 14:15:06
Have a look at this live demo (from jQuery's site). Clicking - (dash) in Firefox says that event.which is 173 , while doing the same in Chrome produces 189 . This jQuery page says that event.which should be normalized for cross browser consistency. But, it looks like this is not true. Why is this inconsistency? This jQuery page says that event.which should be normalized for cross browser consistency. But, it looks like this is not true. jQuery normalizes the property name (e.g., always which , rather than which or keyCode depending on browser), but not the value of the property, which would be