which

How to grep a word exactly

前提是你 提交于 2019-12-17 13:55:47
问题 I'd like to grep for "nitrogen" in the following character vector and want to get back only the entry which is containing "nitrogen" and nothing of the rest (e.g. nitrogen fixation): varnames=c("nitrogen", "dissolved organic nitrogen", "nitrogen fixation", "total dissolved nitrogen", "total nitrogen") I tried something like this: grepl(pattern= "![[:space:]]nitrogen![[:space:]]", varnames) But this doesn't work. I hope somebody can help me with this task. 回答1: To get the indices that are

Which is the best Method used for Sorting? [duplicate]

梦想的初衷 提交于 2019-12-14 03:29:21
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What sort algorithm provides the best worst-case performance? Which is the best method that can be used to sort an Integer array?Is Quick Sort efficient? Some of the common methods used for sorting are mentioned in [spam link removed] 回答1: They are different sorting methods are available with different features. Bubble Sort [It's simple but not good for large data][1] Selection Sort [Selection sort is noted for

What's the tolerance of the which.max function in R?

流过昼夜 提交于 2019-12-13 17:05:41
问题 Based on a problem I discussed here: https://stackoverflow.com/a/57364028/2725773 I'm wondering what's the tolerance/precision of the which.max function in R. Specifically, the alternative max.col function has a tolerance of 1e-5, which means that 0.12345 is the same for it as 0.12346. The help page for max.col suggests an alternative, namely using unname(apply(m, 1, which.max)) , which brings me to the questions what's the tolerance of which.max ? 回答1: Fascinating question. I do not know the

Why is integer(0) outputted when I use the which() function?

半世苍凉 提交于 2019-12-13 03:35:32
问题 I am trying to determine which variables in my V1 column have values in the V5 column that are in the range of 95-105 and also have values in the V6 column that are in the 7-13 range. I am using the which function and attempting to store the names of the variables in V1 under the variable x but I keep getting the output integer(0) or character(0) and I'm not sure what that means. An image of my code is attached below. 回答1: integer(0) means there are no elements of your data frame that satisfy

'which' command in R with case insensitive

两盒软妹~` 提交于 2019-12-13 00:41:34
问题 I am trying to find indexes within a data frame which holds a certain string. But I would like my string to be case insensitive. Say, I want to search for column number in my data frame called COLUMN73 and I expect it to return 73 because it is the seventy third column. I have, which(names(mydata) == "COLUMN73") Is it possible to make my search string case insensitive so as to get 73 even if I search for say, CoLumN73 ? Thanks. 回答1: You can convert your names to upper cases which(toupper

How to Manipulate Array Indexed Values from Matrix in R [duplicate]

左心房为你撑大大i 提交于 2019-12-11 05:31:14
问题 This question already has answers here : Index values from a matrix using row, col indicies (4 answers) Closed last year . Given a matrix mat = matrix(round(runif(min=0,max=1,n=9*9)),ncol=9,nrow=9) say you want all the values of 1 using array indexing indx.1 = which(mat == 1, arr.ind=TRUE) How do you manipulate those index values within your matrix? The below doesn't accomplish what I am after: result.i.dont.want = mat result.i.dont.want[indx.1[,1],indx.1[,2]] = NA because, as far as I can

bash: “which adb” returns nothing, but “command -v adb” returns what i'd expect

笑着哭i 提交于 2019-12-10 14:05:17
问题 This is a bash weirdness that's been bugging me. I'm on OSX. I've installed the android SDK, and as a result the adb tool is located in a folder in my home directory. That folder appears in my path as reported by env as ~/Development/android_sdk_latest/platform-tools . adb itself runs just fine, but when I do which adb the result is empty. If I do command -v adb , the result is the full path, as expected: /Users/me/Development/android_sdk_latest/platform-tools/adb adb does not appear in my

More efficient strategy for which() or match()

爷,独闯天下 提交于 2019-12-09 00:06:08
问题 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

In R, Extract from a matrix all rows indexed by the components of a vector

Deadly 提交于 2019-12-08 05:44:19
问题 In R, let M be the matrix: [,1] [,2] [1,] 1 9 [2,] 3 12 [3,] 6 4 [4,] 7 2 I would like to extract all rows with entries equal to the components of the vector v <- c(3,6,1) from column [,1] in M producing the submatrix m: [,1] [,2] [1,] 1 9 [2,] 3 12 [3,] 6 4 I tried m <- M[which(M[,1] == v), ] obtaining the error message longer object length is not a multiple of shorter object length . Using the transpose t(v) of v does not help. Thanks a lot! Avitus 回答1: using %in% : M[M[,1] %in% v,] [,1] [

dplyr override all but the first occurrences of a value within a group

≡放荡痞女 提交于 2019-12-07 15:50:06
问题 I have a grouped data_frame with a "tag" column taking on values "0" and "1". In each group, I need to find the first occurrence of "1" and change all the remaining occurrences to "0". Is there a way to achieve it in dplyr? For example, let's take "iris" data and let's add the extra "tag" column: data(iris) set.seed(1) iris$tag <- sample( c(0, 1), 150, replace = TRUE, prob = c(0.8, 0.2)) giris <- iris %>% group_by(Species) In "giris", in the "setosa" group I need to keep only the first