An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130308/06ea826f/attachment.pl>
transpose lists
7 messages · PIKAL Petr, ishi soichi, Dimitris Rizopoulos +2 more
Hi
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of ishi soichi Sent: Friday, March 08, 2013 10:50 AM To: r-help Subject: [R] transpose lists Can you think of a function that transposes a list like
What shall be the result of transposed list? Something like lapply(x, t) Regards Petr
x
[[1]] [1] 12.1 0.1 12.0 1.1 [[2]] [1] 3.44 3.00 33.10 23.00 ? ishida [[alternative HTML version deleted]]
______________________________________________ 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130308/250c2b7e/attachment.pl>
two possibilities are:
lis <- list(c(12.1,0.1,12.0,1.1), c(3.44,3.00,33.10,23.00))
# 1st
m <- do.call(rbind, lis)
split(m, col(m))
# 2nd
lapply(seq_along(lis[[1]]),
function (i) sapply(lis, "[", i))
I hope it helps.
Best,
Dimitris
On 3/8/2013 11:06 AM, ishi soichi wrote:
Thanks. The result should be a list of lists like...
x
[[1]] [1] 12.10 3.44 [[2]] [1] 0.1 3.0 [[3]] [1] 12.0 33.1 [[4]] [1] 1.1 23.0 lapply(x, t) doesn't do the job, I think. ishida 2013/3/8 PIKAL Petr <petr.pikal at precheza.cz>
Hi
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of ishi soichi Sent: Friday, March 08, 2013 10:50 AM To: r-help Subject: [R] transpose lists Can you think of a function that transposes a list like
What shall be the result of transposed list? Something like lapply(x, t) Regards Petr
x
[[1]]
[1] 12.1 0.1 12.0 1.1
[[2]]
[1] 3.44 3.00 33.10 23.00
?
ishida
[[alternative HTML version deleted]]
______________________________________________ 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.
[[alternative HTML version deleted]]
______________________________________________ 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.
Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130308/5d0eae6c/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130308/2b98e081/attachment.pl>
Hi, You can try: mat1<- do.call(rbind,x) lapply(seq_len(ncol(mat1)),function(i) mat1[,i]) #[[1]] #[1] 12.10? 3.44 #[[2]] #[1] 0.1 3.0 #[[3]] #[1] 12.0 33.1 #[[4]] #[1]? 1.1 23.0 A.K. ----- Original Message ----- From: ishi soichi <soichi777 at gmail.com> To: PIKAL Petr <petr.pikal at precheza.cz> Cc: r-help <r-help at r-project.org> Sent: Friday, March 8, 2013 5:06 AM Subject: Re: [R] transpose lists Thanks. The result should be a list of lists like...
x
[[1]] [1] 12.10? 3.44 [[2]] [1] 0.1 3.0 [[3]] [1] 12.0 33.1 [[4]] [1]? 1.1 23.0 lapply(x, t) doesn't do the job, I think. ishida 2013/3/8 PIKAL Petr <petr.pikal at precheza.cz>
Hi
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of ishi soichi Sent: Friday, March 08, 2013 10:50 AM To: r-help Subject: [R] transpose lists Can you think of a function that transposes a list like
What shall be the result of transposed list? Something like lapply(x, t) Regards Petr
x
[[1]] [1] 12.1? 0.1 12.0? 1.1 [[2]] [1]? 3.44? 3.00 33.10 23.00 ? ishida ? ? ? [[alternative HTML version deleted]]
______________________________________________ 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.
??? [[alternative HTML version deleted]] ______________________________________________ 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.