Menu
  • HOME
  • TAGS

sed or some other command line tool to remove last occuring /

bash,sed,terminal,which,text-manipulation

The external tool you want to use for this is dirname. So your function would look like this: cwhich() { local bin=$(which "$1") local bindir=$(dirname -- "$bin") cd -- "$bindir" } That being said that's two external tools for this which is two more than you really need here. You...

Using lapply to get minimum values indexes of a list

r,sorting,lapply,which

mapply and match x <- list(a = rnorm(5), b = rnorm(5)) # $a # [1] -0.05417899 -0.28140108 -0.51207379 0.73572854 1.24535765 # # $b # [1] 1.1580326 0.7900556 0.9595224 -1.2232270 0.6621114 y <- lapply(x, sort) # $a # [1] -0.51207379 -0.28140108 -0.05417899 0.73572854 1.24535765 # # $b # [1] -1.2232270 0.6621114...

How to use logical functions with %>% operator (dplyr)

r,logic,dplyr,which

I think it's just an operator precedence issue. The %>% operator has lower precedence than other operators such as ==, so what you're actually doing with aaa == 4 %>% which is passing 4 to the which function ... (aaa == 4) %>% which seems to work just fine ......

which() function in R

r,which

You can do it like that: dfA=data.frame(C1=sample(1:92047), C2=sample(1:92047)) listB=list(sample(1:1829)) dfAinB=dfA[which(dfA$C1 %in% unlist(listB)),] str(dfAinB) ...

which(vector1 < vector2)

r,max,simultaneous,which

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 <- xmaxindx[order(xmaxindx,decreasing=TRUE)] # 2 4 1 3 # 5 4 3 2 Select from those: xmaxindx[vapply(1:6,function(z){ ok <- xvals < z if(length(ok)) which(ok)[1] else NA_integer_...

Mac OS X 10.10 MacPorts Python select

python,osx,macports,which

I'm not sure where your which comes from (check with which which) and whether you implicitly pass any flags to which (check with type which), but that's the output I'd expect if you called which -a python. Btw, if you're trying to find out what your shell is going to...

Boolean operators and which() function in R

r,subset,which

Note that from the helpfile you can read (See ?"|"): For |, & and xor a logical or raw vector... and...For ||, && and isTRUE, a length-one logical vector. Therefore you may want to change your || to | and I think which is not required here. subset_df <- df[...

Subsetting a dataset based on a boolean condition assessed on another dataset, keeping the rows that meets the condition (R)?

r,subsetting,which

You could try (assuming that rows are the rownames of the dataset) df1[colSums(df2)!=0,,drop=FALSE] # something #n1 34 #n2 62 #n3 15 #n5 93 Suppose, if colSums are not 0, this gets all the rows, df2$n4[1] <- 3 df1[colSums(df2)!=0,,drop=FALSE] # something #n1 34 #n2 62 #n3 15 #n4 29 #n5 93...

javascript add keypress (enter) to on()function as event listenner

jquery,keypress,which

Use event.which like this: $(".cartItem-discount").on('focusout keypress mouseleave', '.cartItemPromoCode', function(e){ if(e.which == 13 || e.type == 'mouseleave'){ //do something } }); ...

'which' command in R with case insensitive

r,which

You can convert your names to upper cases which(toupper(names(mydata)) == "COLUMN73") ...

How to avoid for-loops with multiple criteria in function which()

r,performance,for-loop,which,multiple-conditions

You can use dcast from package reshape2, with a custom function to sum your values: library(reshape2) dcast(mydata, name~tag, value.var='value', fun.aggregate=sum) Or simply xtabs, base R: xtabs(value~name+tag, mydata) Some benchmark: funcPer = function(){ S <- matrix(data=NA, nrow=length(unique(mydata$tag)), ncol=length(unique(mydata$name))) for(i in 1:nrow(S)){ for (j in 1:ncol(S)){ foo <- which(mydata$tag == unique(mydata$tag)[i] &...

indexing/linking rows to a unique identifier

r,function,indexing,unique,which

You were almost there. split can be used on the rownames as well. Since they'll be character values, you coerce them to numeric with as.numeric > Indexes <- split(as.numeric(rownames(mydata)), mydata$id) > Indexes[1:2] ## or just 'Indexes' for your sample data ## $`1` ## [1] 1 2 3 4 5 6...

Python - Function “which” from R in Python

python,r,function,which

You can use numpy.where, but it's unnecessary in your use case: In [8]: import numpy as np In [9]: x = np.arange(9.).reshape(3, 3) In [10]: x Out[10]: array([[ 0., 1., 2.], [ 3., 4., 5.], [ 6., 7., 8.]]) In [11]: x[np.where(x>5)] Out[11]: array([ 6., 7., 8.]) In [12]: x[x>5]...

Bash: which returns different location than expected

osx,bash,which

Application lookups are cached. Reset the pip entry: hash pip Quoting man bash: If the name is neither a shell function nor a builtin, and contains no slashes, bash searches each element of the PATH for a directory containing an executable file by that name. Bash uses a hash table...

Cbind/Rbind With Ifelse Condition

r,if-statement,which,cbind

Try t(sapply(x, function(x) if(x=='Yes') y else z)) Or `row.names<-`(t(t(rbind(y,z))[,(x!='Yes')+1L]),x) ...

Wrong behavior of PATH & which

bash,path,which,kali-linux,gnu-coreutils

Most likely bash shell has previous location of basename saved in an internal hash table. To check remembered location of basename use: hash -t basename To force bash to forget the remembered location of basename, use: hash -d basename To force bash shell to forget all remembered locations use: hash...

Subset specific rows with vector of identifiers - warning messages

r,data.frame,subset,which

Your commands depends on equality and this requires an atomic data, but instead you gave a vector. Instead of this, you can use operators as @davidArenburg has mentioned. You can do this by first forming a list of T/F and then retrieve the list according to corresponding value of the...

For a hobby, C# Or C++ [closed]

c#,c++,which

C# is a little easier. I love C++ but it just requires you do so much that doesn't even involve what your task is. Sometimes it requires stuff that doesn't even have to do with the language (hello linker errors). I don't use C# though, so it may be even...

Bash Centos7 “which” command

bash,command,yum,which,centos7

To find a package in CentOS, use yum whatprovides: yum whatprovides *bin/which In this particular case, the package is called which, so yum install which should pull it in....

R function which.max with tapply

r,which,tapply

You can use by and reference the rownames of the row returned by which.max: Data[by(Data, Data$G, function(dat) rownames(dat)[which.max(dat$X)] ),] # X Y G #4 1.595281 -0.3309078 1 #61 2.401618 0.9510128 2 #147 2.087167 0.9160193 3 #171 2.307978 -0.3887222 4 (This assumes set.seed(1) for reproducibility's sake)...

In R, extract the value of column 1 where subsequent columns are max

r,max,apply,which

Convert your data into a "long" format and then use one of the many aggregation functions in R. Here are two approaches with "data.table". First, load the packages required. library(data.table) library(reshape2) Option 1: Keep the data long--more flexible to work with later. (I would prefer this option.) From here, you...

/usr/bin/which has strange behavior when called as python subprocess

python,python-2.7,path,subprocess,which

You are opening the "file" (/dev/null) in the default mode (which is 'r' [read]). However, subprocess is trying to write to the file -- So you probably want: with open(os.devnull, 'w') as nil: p = subprocess.call(['which', 'program'], stdout=nil, stderr=nil) ...