Re: [R] How to invert a list ?

2010-08-16 Thread Carlos Petti
use sapply. > > R can assign names through vectors: > > names(y) <- names(x) > > Or: > > names(y) <- c("NameA","NameB") > > Regards, > > Wu > > > > > From: Carlos Petti [carlos.p

Re: [R] How to invert a list ?

2010-08-11 Thread Carlos Petti
Or rather : n <- sapply(x, function(i) names(i)) tapply(x, n, names) 2010/8/11 Carlos Petti : > A beginning of solution... > > n <- sapply(x, function(i) names(i)) > tapply(x, n, c) > > 2010/8/11 Carlos Petti : >> Thanks. >> >> On the other hand, >&g

Re: [R] How to invert a list ?

2010-08-11 Thread Carlos Petti
A beginning of solution... n <- sapply(x, function(i) names(i)) tapply(x, n, c) 2010/8/11 Carlos Petti : > Thanks. > > On the other hand, > I try to obtain the same result but from this list : > > x <- list() > x$i <- 5 > x$j <- 9 > x$k <- 15 > name

Re: [R] How to invert a list ?

2010-08-11 Thread Carlos Petti
> > I give a handmade code, hope it helps. > > y <- list() > y$a <- a > y$b <- c(b,c) > names(y$a) <- "i" > names(y$b) <- c("j","k") > > > Carlos Petti wrote: >> >> a <- 5 >> names(a) <- "a&q

[R] How to invert a list ?

2010-08-10 Thread Carlos Petti
Dear list, I have a list, as follows : a <- 5 names(a) <- "a" b <- 9 names(b) <- "b" c <- 15 names(c) <- "c" x <- list("i" = a, "j" = b, "j" = c) I want to invert the list, like this : $a i 5 $b j k 9 15 I do not find a clean solution. Could anyone give me elegant ideas ? Thanks in advance

[R] Fwd: List of lists ?

2010-08-10 Thread Carlos Petti
-- Forwarded message -- From: Carlos Petti Date: 2010/8/10 Subject: Re: [R] List of lists ? To: David Winsemius Perhaps a solution : x <- list() x[[2]] <- list() x[[2]][[1]] <- c(1, 2, 3) x[[2]][[2]] <- c(3, 2, 1) 2010/8/10 Carlos Petti : > Thanks for answer.

[R] Fwd: List of lists ?

2010-08-10 Thread Carlos Petti
-- Forwarded message -- From: Carlos Petti Date: 2010/8/10 Subject: Re: [R] List of lists ? To: David Winsemius Thanks for answer. I read the error messages but I did not find the solution :-( Your solution works. But, a new problem remains because I want to use the list of

[R] List of lists ?

2010-08-09 Thread Carlos Petti
Dear list, I have to use a list of lists containing vectors. For instance : [[1]] [[1]][[1]] [1] 1 2 3 [[1]][[2]] [1] 3 2 1 I want to attribute vectors to the main list without use of an intermediate list, but it does not work : x <- list() x[[1]][[1]] <- c(1, 2, 3) x[[1]][[2]] <- c(3, 2, 1

[R] How to name matrices from a list with lapply ?

2010-08-03 Thread Carlos Petti
Dear list, I have a list of matrices : i1 <- matrix(1:10, nrow = 2, ncol = 5) i2 <- matrix(11:20, nrow = 2, ncol = 5) j <- list(i1 = i1, i2 = i2) I would like to attribute names to each dimension, for each matrix, as follows : $i1 B1 B2 B3 B4 B5 A1 1 3 5 7 9 A2 2 4 6 8 10 $i2 B1 B2 B3 B4 B5 A1

Re: [R] Transform contingency table into data.frame ?

2010-03-17 Thread Carlos Petti
Dear list, Thank you for your answers. Petr, your solution works great :-) Peter's solution too. Carlos 2010/3/17 Ivan Calandra > Now I get it, I was still thinking you wanted two columns. I was confused > by the "print" example. > Petr's suggestion works well then > Ivan > > Le 3/17/2010 11

Re: [R] Transform contingency table into data.frame ?

2010-03-17 Thread Carlos Petti
Dear list, Sorry, I did not explain myself very well. I want to obtain a data.frame like this : Freq a1 b1 c1 This data.frame contains just one column (Freq) and each row is named. But when I use this code : df <- as.data.frame(t) or this code : df <- as.data.frame(t, row.names(

[R] Transform contingency table into data.frame ?

2010-03-17 Thread Carlos Petti
Dear list, I have a contingency table : a <- letters[1:3] t <- table(a) I'm looking for a way to transform this table into data frame, as follows : Freq a1 b1 c1 I used : df <- as.data.frame(t, row.names = names(t)) But, this function do not remove the duplicated column. Do you

[R] How to sum a list of matrices ?

2010-03-10 Thread Carlos Petti
Dear list, I have a list of three matrices : i = list(matrix(1:4,2,2), matrix(3:6,2,2), matrix(9:12,2,2)) I would like to sum the matrices, as follows : [,1] [,2] [1,] 13 19 [2,] 16 22 I used this code : k <- i[[1]] for (j in (2:length(i))) { k <- k + i[[j]]} But, is it possible to sum witho

Re: [R] How to match vector with a list ?

2010-03-08 Thread Carlos Petti
r2<-f2(iBig,jBig)) user system elapsed 0.084 0.004 0.088 2010/3/5 William Dunlap > > -Original Message- > > From: r-help-boun...@r-project.org > > [mailto:r-help-boun...@r-project.org] On Behalf Of Carlos Petti > > Sent: Friday, March 05, 2010 9:43 AM > >

[R] How to match vector with a list ?

2010-03-05 Thread Carlos Petti
Dear list, I have a vector of characters and a list of two named elements : i <- c("a","a","b","b","b","c","c","d") j <- list(j1 = c("a","c"), j2 = c("b","d")) I'm looking for a fast way to obtain a vector with names, as follows : [1] "j1" "j1" "j2" "j2" "j2" "j1" "j1" "j2" I used : match <-