[R] Repeating values in a list

Derek Ogle DOgle at northland.edu
Sun Sep 19 03:19:52 CEST 2010


I have a list that looks like this ...

> have <- list(a=7,b=3,c=1)
> have
$a
[1] 7

$b
[1] 3

$c
[1] 1

and I want to have a simple way to change it to the following without re-typing the values ...

> desire <- list(a=c(7,7),b=c(3,3),c=c(1,1))
> desire
$a
[1] 7 7

$b
[1] 3 3

$c
[1] 1 1

In other words, I need to create the list in desire from the list in have.

In my "real" work the number of items in the list may be more than three and the number of times to repeat the numbers may be greater than two.

Thank you in advance for any help you can offer.



More information about the R-help mailing list