[R] converting a list with named member to a vector maintaining original names
baccts at hotmail.com
Tue Jun 24 22:21:47 CEST 2014
You're amazing. Thanks so much! That's exactly what I am looking for.
> From: istazahn at gmail.com
> Date: Tue, 24 Jun 2014 14:32:27 -0400
> Subject: Re: [R] converting a list with named member to a vector maintaining original names
> To: baccts at hotmail.com
> CC: r-help at r-project.org
> How about
> x <- unlist(test)
> (names(x) <- rep(names(test), times = sapply(test, length)))
> See also unlist2 from
> On Tue, Jun 24, 2014 at 12:56 PM, C Lin <baccts at hotmail.com> wrote:
>> Dear R users,
>> I have a list that I'd like to convert to a vector while preserving the original names.
>> For example:
>> test <- list(ABCC2=37280,ABCC5=c(12268,13308));
>> If I do unlist, it automatically renamed the ABCC5 to ABCC51 and ABCC52
>> ABCC2 ABCC51 ABCC52
>> 37280 12268 13308
>> How do I retained the original names so I'll get:
>> ABCC2 37280
>> ABCC5 12268
>> ABCC5 13308
>> Thank you in advance for your help.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help