search for: list1

Displaying 20 results from an estimated 141 matches for "list1".

Did you mean: list
2010 Feb 26
3
Preserving lists in a function
...n R. The function makes use of a lot of lists in its defaults. However, we discovered that R does not necessarily preserve the defaults if we were to input them in the form of list() when initializing the function. For example, if you feed the function codes below into R: myfunction=function( list1=list (variable1=1, variable2=2, variable3=3), list2=list (variable1="variable1", variable2="variable2", variable3="variable3"), list3=list (variable1="character", var...
2009 Oct 30
2
Names of list members in a plot using sapply
Hi R users: I got this code to generate a graphic for each member of a lists. list1<-list(A=data.frame(x=c(1,2),y=c(5,6)),B=data.frame(x=c(8,9),y=c(12,6))) names1<-names(list1) sapply(1:length(list1),function(i) with(list1[[i]],plot(x,y,type="l",main=paste("Graphic of",names1[i])))) Is there a more elegant solution for not to use two separate lists? I w...
2010 Mar 15
1
rbind, data.frame, classes
Hi, This has bugged me for a bit. First question is how to keep classes with rbind, and second question is how to properly return vecotrs instead of lists after turning an rbind of lists into a data.frame list1=list(a=2, b=as.Date("20090102", format="%Y%m%d")) list2=list(a=2, b=as.Date("20090102", format="%Y%m%d")) rbind(list1, list2) #this loses the posixct class. My first question is is there a way to do this without losing the classes? data.frame(rbind(list1, l...
2013 Jan 10
1
merging command
HI Eliza, You could do this: set.seed(15) mat1<-matrix(sample(1:800,124*12,replace=TRUE),nrow=12) # smaller dataset #Your codes ?list1<-list() ?for(i in 1:ncol(mat1)){ ? list1[[i]]<-t(apply(mat1,1,function(x) x[i]-x)) ? list1} ?x<-list1?? x<-matrix(unlist(x),nrow=12) x<-abs(x) ?y<-colSums(x, na.rm=FALSE) z<-matrix(y,ncol=10) ?z<-as.dist(z) ?z ?# ?? 1?? 2?? 3?? 4?? 5?? 6?? 7?? 8?? 9 #2? 319?????????????????...
2011 Jan 08
3
Question on list objects
...- matrix(1:9,3)   Now I want to replicate this entire matrix 3 times and put entire result in a list object. Means, if "res" is the resulting list then I should have:   res[[1]]=dat, res[[2]]=dat, res[[3]]=dat   How can I do that in the easilest manner?   2. Suppose I have 2 list objects: list1 <- list2 <- vector("list", length=2) for(i in 1:2) {   list1[[i]] <- matrix(rnorm(15), 3)   list2[[i]] <- matrix(rnorm(15), 3)  } How can I add these 2 list objects? I have tried with just list1+list2, however it is generating some error.   Would be grateful for any help.   T...
2007 Oct 15
1
The "condition has length > 1" issue for lists
I have the following code: list1 <- list() for (i in list.files(pattern="filename1")){ x <- read.table(i) list1[[i]] <- x } list2 <- list() for (i in list.files(pattern="filename2*")){ x <- read.table(i) list2[[i]] <- x } anslist <- vector('list', length(list1)) for(i i...
2012 Nov 08
3
Extracting columns
Hi, I have 22 files (A1, A2, ..., A22) with different number of columns, totaling 10,000 columns: c1, c2, c3, ..., c10000 I have another file with a list of 100 columns that I need to extract. These 100 columns are distributed in 22 files. How to extract the 100 columns of the 22 files? I have done it "manually" with the following commands, for example: cromo1 = read.table ("~
2011 Jan 20
1
syntax for a list of components from a list
I'm attempting to generalise a function that reads individual list components, in this case they are matrices, and converts them into 3 dimensional array. I can input each matrix individually, but want to do it for about 1,000 of them ... This works array2 <- abind(list1[[1]],list1[[2]],list1[[3]],along=3) This doesn't array2 <- abind(list1[[1:3]],along=3) This doesn't either array2 <- abind((list1[[1]]:(list1[[3]]),along=3) Any thoughts how I can make this work for larger numbers? Thanks J =============================== Dr. Jim Maas University...
2011 Nov 21
1
Creating a list from all combinations of two lists
R-helpers: Say I have two lists of arbitrary elements, e.g.: list1=list(c(1:3),"R is fun!",c(3:6)) list2=list(c(10:5),c(5:3),c(13,5),"I am so confused") I would like to produce a single new list that is composed of all combinations of the "top level" of list1 and list2, e.g.: listcombo=list(list(list1[[1]],list2[[1]]),list(list1[[...
2011 Feb 06
1
Applying 'cbind/rbind' among different list object
Hi, I am wondering whether we can apply 'cbind/rbind' on many **equivalent** list objects. For example please consider following: > list1 <- list2 <- vector("list", length=2); names(list1) <- names(list2) <- c("a", "b") > list1[[1]] <- matrix(1:25, 5) > list1[[2]] <- matrix(2:26, 5) > list2[[1]] <- 10:14 > list2[[2]] <- 11:15 > list1 $a [,1] [,2] [,3] [,4] [,5]...
2011 Feb 08
2
Extrcat selected rows from a list
Hi, I have two lists 1) List1- 30,000 rows and 104 columns 2) List2- a list of 14000 selected rownames  from List 1 Now, I want to extract all the 104 columns of List1  matching with the 14000 selected rownames from List2.  Psedocode will be something like this: match rownames(List2) with rownames(List1) extract selected m...
2009 Apr 15
6
Intersection of two sets of intervals
Hi, Algorithm question: I have two sets of "intervals", where an interval is an ordered pair [a,b] of two numbers. Is there an efficient way in R to generate the intersection of two lists of same? For concreteness: I'm representing a set of intervals with a data.frame: > list1 = as.data.frame(list(open=c(1,5), close=c(2,10))) > list1 open close 1 1 2 2 5 10 > list2 = as.data.frame(list(open=c(1.5,3), close=c(2.5,10))) > list2 open close 1 1.5 2.5 2 3.0 10.0 How do I get the intersection which would be something like: open close 1...
2012 Apr 19
1
question about lists
I am new to R, and I have been running into the following situation when I mistype a variable name in some code: > list1 <- list( a=1, b=2 ) > list2 <- list( a=1 ) > list2$b <- list1$c > list2 $a [1] 1 I would think at the point where I am trying to reference a field called "c" -- that does not exist -- in list1, there would be an error flagged. Instead, list1$c returns value NULL, and t...
2006 Jun 26
0
sortables and accept question
i did some searching through the archives and didn''t really find an answer to my question, so i''m going to just ask it. i have a situation where there are 3 sortable lists. list1, list2, and list3 i need list2 to accept divs from all 3 lists, but list1 and list3 to only accept divs from the list1 and list3 i''ve added two classes to the divs in my sortables: .rail for list1 and list3, and .center for list2. i then added the appropriate accept options to my sorta...
2004 Jan 24
1
loop variable passage and lists
I cannot understand why the following expression is accepted (and gives the expected result: to set column 3 and 4 of the first element of list1 -a data.frame list- as first element of list2): > list2[[1]]<-list1[[1]][3:4] ...while this one is not (to do the same iteratively from the first to the eleventh element of list1): > for (i in 1:11){list2[[i]]<-list1[[i]][3:4]} Error in "[.data.frame"(list1[[i]], 3:4) :...
2013 Jan 08
4
Logical operator and lists
Hello R-Helpers, I have a slight problem with the expresion data[data==""] <- NA which works well for a data.frame. But now i must use the same for a list of data.frames. My idea is data[[]][data==""] but it don´t work. Thanks!! Dominic [[alternative HTML version deleted]]
2004 Oct 25
1
usage and behavior of 'setIs'
Hello, am I using 'setIs' in the correct way in the subsequent (artifical) example? Do I have to specify explicit 'setAs' for 'list' and 'vector' or should this work automatically, since "getClass("List1")" states an explicit coerce also for these classes. I'm working with R 2.0.0 Patched (2004-10-06) on windows 2000. Thanks for your advice, Matthias # example setClass(Class = "List1", representation(List = "list")) setClass(Class = "List2", contains...
2007 May 16
2
substitute "x" for "pattern" in a list, while preservign list "structure". lapply, gsub, list...?
...he "structure" of the original list. What is a good way to accomplish this? I tried : a = matrix(data=c(23,45,'red',78),nrow=2) b = c('red','green',1,2,3) d = data.frame( test1=c(223,445,'red',78,56) , test2= c('red',NA,NA,NA,NA) ) e= list(a,b,d) list1 = list(a,b,d,e) list2 = lapply(list1,function(list)(gsub("red","green",list))) str(list1) str(list2) but the structue fo the list changed. --------------------------------- Give spam the boot. Take control with tough spam protection [[alternative HTML version delet...
2005 Sep 23
1
Sortable list with Ajax and delete function - working example
Hi. I read most of the postings here but unfortunately I didin''t found a complete example which could be used. Of cource the ones who are professionals in javascript could implement the missing peaces from the puzzle. What I''m required to do is a tree (sortable list) where items can also be deleted and at each modification a function (ajax) is called to save the changes. For
2012 Nov 13
2
multiply each row in a matrix with the help of the for loop
Dear R users, I have this program aa<-array(rep(0,27),dim=c(3,3,3)) a<-matrix(rep(1,9),ncol=3) n<-0 for (i in 1:3) {            a[i,]<-a[i,]*(-1)       n<-n+1       aa[,,n]<-a[i,] } but i real want to multiply each row  with -1 according to for loop and after that to put it in the array.  I will give an example for what excaclty want -1 -1 -1  1  1  1  1  1  1 -1 -1 -1 -1