similar to: get index of current element in vector

Displaying 20 results from an estimated 20000 matches similar to: "get index of current element in vector"

2012 Jul 19
1
[tripack] error in trmesh
I am trying to triangulate a point set as follows: > head(cbind(x,y)) x y [1,] -78.1444 -60.4424 [2,] -78.1444 -58.4424 [3,] -78.1444 -56.4424 [4,] -78.1444 -54.4424 [5,] -76.1444 -60.4424 [6,] -76.1444 -58.4424 > length(x) [1] 5000 > tri <- tri.mesh(x, y) Fehler in tri.mesh(x, y) : error in trmesh > tri <- tri.mesh(x, y, "remove") Fehler in tri.mesh(x, y,
2012 Jul 23
1
[RCurl] HTTP 404 Status
I am trying to get contents of a REST response: getURL("http://localhost/myweb-app/rest-ws") This is a web application (myweb-app) which is providing a REST web service (rest-ws)... Unfortunately, the HTTP status sent back is 404. If I request the url using Chrome/IE, I get a HTTP status 200 OK. In Opera the request does not succeed either. I am using 2.15.1 (Win7, 64Bit) and just
2012 Jul 18
1
convert deldir$delsgs to a X3D IndexedTriangleSet
Anyone knows how to convert a deldir$delsgs to a X3D IndexedTriangleSet? Are there already any functions/packages? [[alternative HTML version deleted]]
2007 Jun 13
1
passing (or obtaining) index or element name of list to FUN in lapply()
Hello everyone, I wonder if there is a way to pass the index or name of a list to a user-specified function in lapply(). For instance, my desired effect is something like the output of > L <- list(jack=4098,sape=4139) > lapply(seq(along=L),function(i,x) if(i==1) "jack" else "sape",x=L) [[1]] [1] "jack" [[2]] [1] "sape" >
2010 Sep 13
3
Question: Form a new list with the index replicated equal to the number of elements in that index
Dear R-Helpers, I have a list l1 like: l1[[1]] a b c l1[[2]] d l1[[3]] e f I want an output res like: res[[1]] 1 1 1 res[[2]] 2 res[[3]] 3 3 Essentially, I want to replicate each index equal to the number of elements present in that index. Below is what I do to accomplish this: l1 <- list(c("a", "b", "c"), "d", c("e", "f"))
2012 Nov 16
4
Multiple Vector with matrix in R
Hi Can someone show me an easy way to multiple a weighted vector with an matrix? example below mat1<-matrix(sample(1:100,80,replace=TRUE),ncol=8) w <- 1/1:10 I want the first element in w to be multiplied by the first row of mat1 and 2nd element in w to be multiplied with the 2nd row and so on. I have huge matrix is there an easy way other than diag(w)%*%mat1 Thanks -- View this
2006 Aug 15
2
Extracting the current value of a DOM element
So, say I have two select boxes. One with the letters of the alphabet, and a second with a list of names. When I select the letter in the first, how do I, in my onChange function, extract the value I selected in the first box, to determine what values to populate the second box with? I don''t want to submit the form, I''d like to do this with Ajax. Thanks in advance, Ben. --
2013 Oct 11
3
matrix values linked to vector index
Hi, In the example you showed: m1<- matrix(0,length(vec),max(vec)) 1*!upper.tri(m1) #or ?m1[!upper.tri(m1)] <-? rep(rep(1,length(vec)),vec) #But, in a case like below, perhaps: vec1<- c(3,4,5) ?m2<- matrix(0,length(vec1),max(vec1)) ?indx <- cbind(rep(seq_along(vec1),vec1),unlist(tapply(vec1,list(vec1),FUN=seq),use.names=FALSE)) m2[indx]<- 1 ?m2 #???? [,1] [,2] [,3] [,4] [,5]
2008 Jun 05
1
negative indexing with null index sets
Negative indexing is often handy, but I'm in need of an appropriate idiom for handling cases in which the index set can be null: x <- rnorm(5) a <- 1:5 s <- rep(FALSE,5) y <- x[-a[s]] # I'd like y == x but instead one has x[-a[s]] == x[a[s]] == numeric(0), which is rather # unfortunate -- so far the best I have come up with is: as <- ifelse(length(a[s]),-a[s],TRUE)
2008 Nov 08
2
Data Manipulation, add frequency index
Hi, there, I have a simple data manipulation question for you. Thank you for your help! Suppose that I have this data about people appearing in a class Mary Mary Mary Sam Sam John John John John Then I want to find out what exact time(s) the student appears at the moment such as Mary 1 Mary 2 Mary 3 Sam 1 Sam 2 John 1 John 2 John 3 John 4 the fifth row shows tha Sam show the second times
2012 Aug 28
5
return first index for each unique value in a vector
I would like to efficiently find the first index of each unique value in a very large vector. For example, if I have a vector A<-c(9,2,9,5) I would like to return not only the unique values (2,5,9) but also their first indices (2,4,1). I tried using a for loop with which(A==unique(A)[i])[1] to find the first index of each unique value but it is very slow. What I am trying to do is easily
2012 Apr 05
3
Apply function to every 'nth' element of a vector
Dear R users, how do I e.g. square each second element of a vector with an even number of elements? Or more generally to apply a function to every 'nth' element of a vector. I looked into the apply functions, but found no hint. For example: v <- c(1, 2, 3, 4) mysquare <- function (x) { return (x*x) } w <- applyfun(v, mysquare, 2) then w should be c(1, 4, 3, 16) Thanks for
2010 Apr 08
2
Problem using elements in a vector
Hi So my particular problem is this: I have a row vector of length 5200 elements - specifically created by x<-rbinom(5200,1,0.5) y<-matrix(x,nrow=1,ncol=5200) y now, each element is either a 0 or a 1 - e.g. it could be (0,1,1,1,1,0,0,0,1,1,1) e.t.c. when the element is a 1, i need to multiply a number (say 1000) by 1.005, and if it is 1 again, multiply it _again_ by 1.005. so for
2010 Apr 08
1
Question on using elements of a vector
Hi So my particular problem is this: I have a row vector of length 5200 elements - specifically created by x<-rbinom(5200,1,0.5) y<-matrix(x,nrow=1,ncol=5200) y now, each element is either a 0 or a 1 - e.g. it could be (0,1,1,1,1,0,0,0,1,1,1) e.t.c. when the element is a 1, i need to multiply a number (say 1000) by 1.005, and if it is 1 again, multiply it _again_ by 1.005. so
2012 Nov 05
2
averaging a list of matrices element wise
Dear all, I have a list of n matrices which all have the same dimension (r x s). What would be a fast/elegant way to calculate the element wise average? So result[1, 1] <- mean(c(raw[[1]][1, 1] , raw[[2]][1, 1], raw[[...]][1, 1], raw[[n]][1, 1])) Here is my attempt. #create a dummy dataset n <- 3 r <- 5 s <- 6 raw <- lapply(seq_len(n), function(i){ matrix(rnorm(r * s), ncol =
2012 Nov 30
1
xts indexed with Date class
Hi I see a changed behaviour in xts indexed on class Date in the latest versions, versus 2. It seems to be related to changes to/from daylight savings time, happens those weekends. Is it not intended that class Date be used like this, or is this new behaviour incorrect? Giles Example: > a<-as.Date(15423:15426) > x<-xts(seq_along(a),a) > print(x) [,1] 2012-03-24
2009 Nov 22
2
Help with indexing
Dear R Helpers, I am missing something very elementary here, and I don't seem to get it from the help pages of the ave, seq and seq_along functions, so I wonder if you could offer a quick help. To use an example from an earlier post on this list, I have a dataframe of this kind: dat = data.frame(name = rep(c("Mary", "Sam", "John"), c(3,2,4))) dat$freq =
2009 Nov 11
1
How to get the names of list elements when iterating over a list?
I need to get the names of the list elements when I iterate over a list. I'm wondering how to do so? alist=list(a=c(1,3),b=c(-1,3),c=c(-2,1)) sapply(alist,function(x){ #need to use the name of x for some subsequent process })
2012 Jun 12
4
How to index a matrix with different row-number for each column?
here's my question: suppose I have a matrix: mt<-matrix(1:12,ncol=6) now I have a vector vt<-c(1,2,2,2,1,2) which means I want to get: the 1st row for column1; the 2nd row for column2; the 2nd row for column3; the 2nd row for column4; ... that what I want is this vector: 1,4,6,8,9,12 Does anyone know how to do this fast? I know I can use for-loop to travel all columns,but
2011 Jan 03
3
matrices call a function element-wise
Hello I have 4 1000*1000 matrix A,B,C,D. I want to use the corresponding element of the 4 matrices. Using the "for loop" as follow: E<-o for (i in 1:1000) {for (j in 1:1000) { E<-fisher.test(matrix(c(A[i][j],B[i][j],C[i][j],D[i][j]),2))#call fisher.test for every element } } It is so time-consuming Need vectorization Yours sincerely ZhaoXing Department of