similar to: flatten lists

Displaying 20 results from an estimated 4000 matches similar to: "flatten lists"

2012 Aug 01
4
apply function over same column of all objects in a list
Hello. Please forgive me if this problem has already been posted (and solved) by someone else ... I can't find it anywhere though it seems so very basic. Here it is: I have a list comprised of several matrices, each of which has two columns. > list [[1]] [,1] [,2] [1,] 1 3 [2,] 2 4 [[2]] [,1] [,2] [1,] 5 7 [2,] 6 8 [[3]] [,1] [,2]
2010 Jan 08
1
how to flatten a list to the same level?
I have a nested list l like: l <- list(A=c(1,2,3), B=c("a", "b")) l <- list(l,l, list(l,l)) I want the list to be unlisted, but not on the lowest level of each "branch". I want the lowest level of each list branch to remain as it is. So unlist or unlist(rec=F) do not work here as the level of nesting may differ on the elements. The result should look like:
2010 Nov 02
2
on the usage of do.call
Hello all, I don't know if it is possible, but I would like to use do.call in C code in my package. The function do.call is defined as > do.call function (what, args, quote = FALSE, envir = parent.frame()) { if (!is.list(args)) stop("second argument must be a list") if (quote) { enquote <- function(x) as.call(list(as.name("quote"),
2004 Sep 16
5
Indexing lists
DeaR useRs: I have a list with 500 elements, in each other there are data.frames and I want to take the first row and the first column of each elements of my list since the first to the 500-th. Thanks and excuse my bad English. --- [[alternative HTML version deleted]]
2012 Mar 15
3
single, double or no quotes in expression
Dear all, I am confused about how to create an expression. I use a package (rsbml) which uses expressions and seems to make a difference if there is a quote around the expression or not. For example, package works with expressions such as > expression(A + B) but not with > expression("A + B") I now have a set of math expressions represented as strings, something like this: >
2011 May 19
0
Flattening lists and environments (was: "how to flatten a list to the same level?")
Dear list, I came up with a two functions that flatten arbitrary deeply nested lists (as long as they're named; not tested for unnamed) and environments (see attachment; 'flatten_examples.txt' contains some examples). The paradigm is somewhat similar to that implemented in 'unlist()', yet extends it. I would have very much liked to build upon the superfast functionality
2008 Jun 11
7
applying a function recursively
Hi, I have a question about applying a function recursively through a list. Suppose I have a list where the different elements have different levels of recursion: > test.list<-list("I"=list("A"=c("a", "b", "c"), "B"=c("d", "e", "f"), "C"=c("g", "h", "i")), +
2008 Dec 31
1
Problem with package SNOW on MacOS X 10.5.5
Hello All, I can run the "lower level" functions OK, but many of the higher level (eg. parSApply) functions are generating errors. When running the example (from the snow help docs) for parApply on MacOSX 10.5.5, I get the following error: cl <- makeSOCKcluster(c("localhost","localhost")) sum(parApply(cl, matrix(1:100,10), 1, sum)) Error in
2011 Jun 12
1
snow package
Hi I try parallelising some code using the snow package and the following lines: cl <- makeSOCKcluster(8) pfunc <- function (x) (if(x <= (-th)) 1 else 0) ###correlation coefficient clusterExport(cl,c("pfunc","th")) cor.c.f <- parApply(cl,tms,c(1,2),FUN=pfunc) The parApply results in the error message: > cor.c.f <- parApply(cl,tms,c(1,2),FUN=pfunc) Error
2010 Dec 02
1
parLapply - Error in do.call("fun", lapply(args, enquote)) : could not find function "fun"
Hello everybody, I've got a bit of a problem with parLapply that's left me scratching my head today. I've tried this in R 2.11 and the 23 bit Revolution R Enterprise and gotten the same result, OS in question is Windows XP, the package involved is the snow package. I've got a list of 20 rain/no rain (1/0) situations for these two stations i and j, all the items in this list look
2010 Apr 09
1
Rsge: recursive parallelization
In principle, I'd like to be able to do something like this: sge.parLapply(seq(10), function(x) parLapply(seq(x), function(x) x^2)) In practice, however, I have to resort to acrobatics like this: sge.options(sge.remove.files=FALSE) sge.options(sge.qsub.options='-cwd -V') sge.parLapply(seq(10), function(x) { sge.options(sge.save.global=TRUE)
2015 May 04
2
Define replacement functions
Hello I tried to define replacement functions for the class "mylist". When I test them in an active R session, they work -- however, when I put them into a package, they don't. Why and how to fix? make_my_list <- function( x, y ) { return(structure(list(x, y, class="mylist"))) } mylist <- make_my_list(1:4, letters[3:7]) mylist mylist[['x']] <- 4:6
2005 Feb 03
5
How to convert a list to a matrix
Hi Sorry to ask such a basic question. I have a list, each element of which is a vector of two values. What I actually want is a matrix with two columns, and one row per element of the list. Obviously I have tried as.matrix(), and as.vector() but I didn't expect the latter to work. I feel so lame asking this. Any suggestions? Mick
2009 Oct 25
3
NULL elements in lists ... a nightmare
I can define a list containing NULL elements: > myList <- list("aaa",NULL,TRUE) > names(myList) <- c("first","second","third") > myList $first [1] "aaa" $second NULL $third [1] TRUE > length(myList) [1] 3 However, if I assign NULL to any of the list element then such element is deleted from the list: > myList$second <-
2017 Jun 15
4
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi I have a list : mylist <- list( a = NULL, b = 1, c = 2 ) > mylist[1] $a NULL > is.null(mylist[1]) [1] FALSE > is.null(mylist$a) [1] TRUE why? I need to use mylist[1]
2004 May 10
2
Lists and outer() like functionality?
Hi, I'm have a list of integer vectors and I want to perform an outer() like operation on the list. As an example, take the following list: mylist <- list(1:5,3:9,8:12) A simple example of the kind of thing I want to do is to find the sum of the shared numbers between each vector to give a result like: result <- array(c(15,12,0,12,42,17,0,17,50), dim=c(3,3)) Two for() loops is the
2007 Oct 20
1
Getting at what a named object represents in a function...
Hi, I'm pretty new to R. I have an object (say a list) and I I have a function that I call on various columns in that list (excuse terminology if it's wrong/ambiguous). Imagine its like this (actual values are unimportant) and called mylist: >mylist A B 1 5 2 5 3 6 4 8 5 0 I have a function: foo = function(param){ #modify list A or B values depending on
2011 Apr 05
1
Help in splitting a list
Dear R users, Let's say I have a list with components being 'm' matrices (as exemplified in the "mylist" object below). Now, I'd like to subset this list based on an index vector, which will partition each matrix 'm' in 2 sub-matrices. My questions are: 1. Is there an elegant way to have the results shown in mylist2 for an arbitrary number of matrices in mylist?
2001 Oct 18
2
Parsing for list components
How do I parse an identifier of a list component, e.g. mylist$mycomponent or mylist[[1]] ? Parse does not do the job, e.g. parse(text="mylist$mycomponent") returns an expression with just one term, instead of "mylist", "$", "mycomponent". What I need is a way to extract the list name (e.g. "mylist"), given an identifier of a component.
2010 Sep 04
4
Please explain "do.call" in this context, or critique to "stack this list faster"
I've been doing some consulting with students who seem to come to R from SAS. They are usually pre-occupied with do loops and it is tough to persuade them to trust R lists rather than keeping 100s of named matrices floating around. Often it happens that there is a list with lots of matrices or data frames in it and we need to "stack those together". I thought it would be a simple