If I combine elements into a list

b <- c(22.4, 12.2, 10.9, 8.5, 9.2)
my.c <- sample.int(round(2*mean(b)), 5)
my.list <- list(b, my.c)

the names of the elements seems to get lost in the process:

> str(my.list)
List of 2
 $ : num [1:5] 22.4 12.2 10.9 8.5 9.2
 $ : int [1:5] 11 8 6 9 20

If I explicitly name the elements at list-creation, I get what I want:

my.list <- list(b=b, my.c=my.c)

> str(my.list)
List of 2
 $ b   : num [1:5] 22.4 12.2 10.9 8.5 9.2
 $ my.c: int [1:5] 11 8 6 9 20


Now, is there a way to get list() (or some other function) to
automatically name the elements?

I often use list() in return(), and I am getting tired of having to
repeat myself.

-- 
Hans Ekbrand (http://sociologi.cjb.net) <h...@sociologi.cjb.net>
A. Because it breaks the logical sequence of discussion
Q. Why is top posting bad?

Attachment: signature.asc
Description: Digital signature

______________________________________________
R-help@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.

Reply via email to