similar to: using a list to index elements of a list

Displaying 20 results from an estimated 50000 matches similar to: "using a list to index elements of a list"

2009 Oct 14
2
Getting indeices of intersecting elements.
Hi, Is there a command to get the indices of intersecting elements of two vectors as intersect() will give the elements and not its indices. Thanks in advance. Praveen Surendran School of Medicine and Medical Sciences University College Dublin Belfield, Dublin 4 Ireland. [[alternative HTML version deleted]]
2011 Feb 10
3
modifynig some elements of a vector
He everybody, I want to add 1 to some elements of a vector: x is a vector u is a vector of idices, that is, integers assumed to be within the range 1..length(x) and I want to add 1 to the elements of x each time their index appears in u x[u]<-x[u]+1 works only when there are no duplicated values in u I found this solution: tu <- table(u) indices <- as.numeric(names(tu)) x[indices]
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 Nov 19
2
generated list element names
How can I create lists with element names created on the fly? --8<---------------cut here---------------start------------->8--- > list (foo = 10) $foo [1] 10 > list ("foo" = 10) $foo [1] 10 > list (paste("f","oo",sep="") = 10) Error: unexpected '=' in "list (paste("f","oo",sep="") ="
2010 Apr 30
3
replace elements in a list
Dear all, I have a list like this: l <- list(list(a=1,b=NULL), list(a=2,b=2)) I want to find out the elements with value of NULL and replace them with NA. The actual case has a very long list, so manually find out and replace them is not an option. I can use for loop to do this, but I want to know if there is vectorized way (or other ways) to do it? Thanks -- Wincent Rong-gui HUANG Doctoral
2011 Feb 04
3
lapply, strsplit, and list elements
Hi there, I have a problem about lapply, strsplit, and accessing list elements, which I don't understand or cannot solve: I have e.g. a character vector with three elements: x = c("349/077,349/074,349/100,349/117", "340/384.2,340/513,367/139,455/128,D13/168", "600/437,128/903,128/904") The task I want to perform, is to generate a list,
2013 Feb 12
3
grabbing from elements of a list without a loop
Hello! # I have a list with several data frames: mylist<-list(data.frame(a=1:2,b=2:3), data.frame(a=3:4,b=5:6),data.frame(a=7:8,b=9:10)) (mylist) # I want to grab only one specific column from each list element neededcolumns<-c(1,2,0) # number of the column I need from each element of the list # Below, I am doing it using a loop: newlist<-NULL for(i in 1:length(mylist) ) {
2012 Oct 16
1
Question about use of sort.list(sort.list(x)) in rank.r
I was looking at rank() and I came across: ... "first" = sort.list(sort.list(xx)), ... line 32 of rank.r [1] sort.list(x) returns the indices of the values of x in ascending (by default) order. So sort.list(sort.list(x)) returns the same list. So, what am I missing here? -Tyler [1] view-source:http://svn.r-project.org/R/trunk/src/library/base/R/rank.R [[alternative HTML version
2009 Sep 10
2
index of min elements in matrix
Hi, All, How can I get the indices of the minimum elements in a matrix without using a loop? For example, if the matrix is 4 5 2 2 8 9 5 2 3 Then I want to output (1,3), (2,1), (3,2). Thanks, Annie [[alternative HTML version deleted]]
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
2009 Nov 19
2
Efficient cbind of elements from two lists
Hi! I have a data.frame "data" and splitted it. data <- split(data, data[,1]) This is a quite slow procedure; and I do not want to do it again. So, any unsplit and "resplit" is no option for me. But: I have to cbind "variables" to the splitted data from another list, that contains of vectors with matching sizes, so for (i in 1:length(data)) { data[[i]]
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 Mar 24
0
R-help ordinal regression
Dear colleagues, i am carrying out an ordinal regression model. I try it on SPSS but I "flirt" with R as well. I have a few questions. 1. What is the most reliable/tested/trusted package for ordinal regression in the R world? 2. Also, I have a statistical question. What is the danger of having to many 'empty cells' in ordinal regression? How many empty cells are too many? Do
2013 Feb 03
2
Compare each element of a list to a vector
Hello R-helpers, I have a vector x<-c(1,2,3) and a list that contains vectors datalist<-list(c(1,2,3),c(2,3,4),c(3,4,5),c(4,5,6)) and I would like to identify those list elements that are identical to x. I tried > datalist %in% x [1] FALSE FALSE FALSE FALSE but I am obviously using %in% incorrectly. I also tried messing around with lapply but I can't figure out how to specify
2010 Jan 11
2
help needed to find zero areas in a vector
Dear Helpers:   I spend more than half a day to solve this problem in R:   Let x be a vector of a string of 0s and 1s, such as x<-c(0,0,1,1,0,0,0,0,1,1,0,0,0,0). It can be a very long vector. How to sub vectors of 0s? In the above example, I would like get the vectors (0,0), (0,0,0,0), (0,0,0,0). I can use which(x==0) to get the index of the 0 elements, but I don't know how to get the
2010 Aug 24
1
Index list by other list (w/ logical elements)?
I have two lists of the same shape, like this: x <- list() x[[1]] <- c("one","two") x[[2]] <- c("three","four","five") y <- list() y[[1]] <- c(TRUE,FALSE) y[[2]] <- c(FALSE,TRUE,TRUE) I would like to index x "by" y, that is, the result in this case should be: z [[1]] [1] "one" [[2]] [1] "four"
2009 Nov 25
5
How to sum only a few elements in a line
Hello, I have a matrix with the numbers 0,1 and 9 I would like to write a function that could sum each line skiping everytime a number 9 appears for example [0 1 0 1 1 9 1] the sum would be 4. However I cannot replace 9 by 0 otherwise after the sum is done I wouldn?t be able to distiguish which ones were real zeros and which ones were nines replaced by zero just to sum. Thank you very much --
2017 Jun 23
2
Simple control structure issue
I am having a hard time with 'next'. I come from the "sloppy" school that learned BASIC with Goto. Conceptually next seems pretty straightforward. I just can't get it to work correctly in my code. Here's a stripped down version: WhichRunNow<-"Daily" Cnums=c(0,1,"2b3") Cpers=c("Daily","Daily","Weekly") for (j in
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"))
2008 Feb 12
4
assigning NULLs to elements of a list
Dear developers: I have just came across an (unexpected to me) behaviour of lists when assigning NULLs to list elements. I understand that a NULL is a valid R object, thus assigning a NULL to a list element should yield exactly the same result as assigning any other object. So I was surprised when assigning a NULL in fact removed the element from the list. Is this an intended behaviour? If