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
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)
-- Forwarded message --
From: Carlos Petti carlos.pe...@gmail.com
Date: 2010/8/10
Subject: Re: [R] List of lists ?
To: David Winsemius dwinsem...@comcast.net
Thanks for answer.
I read the error messages but I did not find the solution :-(
Your solution works.
But, a new problem
-- Forwarded message --
From: Carlos Petti carlos.pe...@gmail.com
Date: 2010/8/10
Subject: Re: [R] List of lists ?
To: David Winsemius dwinsem...@comcast.net
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
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,
Carlos
()
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
b - 9
names(b) - b
c - 15
names(c) - c
x - list(i = a, j = b, j = c)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-invert-a-list
A beginning of solution...
n - sapply(x, function(i) names(i))
tapply(x, n, c)
2010/8/11 Carlos Petti carlos.pe...@gmail.com:
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
names(x$i) - a
names(x$j) - b
names(x$k
Or rather :
n - sapply(x, function(i) names(i))
tapply(x, n, names)
2010/8/11 Carlos Petti carlos.pe...@gmail.com:
A beginning of solution...
n - sapply(x, function(i) names(i))
tapply(x, n, c)
2010/8/11 Carlos Petti carlos.pe...@gmail.com:
Thanks.
On the other hand,
I try to obtain
) - c(NameA,NameB)
Regards,
Wu
From: Carlos Petti [carlos.pe...@gmail.com]
Sent: Wednesday, August 11, 2010 5:39 AM
To: Wu Gong
Cc: r-help@r-project.org
Subject: Re: [R] How to invert a list ?
Or rather :
n - sapply(x, function(i) names(i
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 - lapply(j, function (x) {which(i %in% x)})
))
user system elapsed
0.084 0.004 0.088
2010/3/5 William Dunlap wdun...@tibco.com
-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
To: r-help@r-project.org
Subject: [R] How
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
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
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,
Dear list,
Thank you for your answers.
Petr, your solution works great :-)
Peter's solution too.
Carlos
2010/3/17 Ivan Calandra ivan.calan...@uni-hamburg.de
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
15 matches
Mail list logo