Hi all,
I have an object that looks (roughly) like the following:
l <- list(a = matrix(rnorm(9), 3), b = matrix(rnorm(9), 3), c =
matrix(rnorm(9), 3))
l$a[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
l$b[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
l$c[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
rownames(l$a) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
rownames(l$b) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
rownames(l$c) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
colnames(l$a) <- c("V1", "V2", "V3")
colnames(l$b) <- c("V1", "V2", "V3")
colnames(l$c) <- c("V1", "V2", "V3")
I want to extract values (row1, V1) for the three sublists a, b, c,
but only for those cases in which row3 == "Message 1". Could someone
suggest how to proceed?
Many thanks in advance,
Lara
subsetting a list of matrices
3 messages · Lara Poplarski, Henrique Dallazuanna, Justin Haynes
Try this: subset(as.data.frame(do.call(rbind, lapply(l, "[", , 1))), row3 == "Message 1")
On Tue, Aug 23, 2011 at 1:28 PM, Lara Poplarski <larapoplarski at gmail.com> wrote:
Hi all,
I have an object that looks (roughly) like the following:
l <- list(a = matrix(rnorm(9), 3), b = matrix(rnorm(9), 3), c =
matrix(rnorm(9), 3))
l$a[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
l$b[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
l$c[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
rownames(l$a) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
rownames(l$b) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
rownames(l$c) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
colnames(l$a) <- c("V1", "V2", "V3")
colnames(l$b) <- c("V1", "V2", "V3")
colnames(l$c) <- c("V1", "V2", "V3")
I want to extract values (row1, V1) for the three sublists a, b, c,
but only for those cases in which row3 == "Message 1". Could someone
suggest how to proceed?
Many thanks in advance,
Lara
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110823/7b78a22c/attachment.pl>