[R] How to assign names in a list

0 views
Skip to first unread message

john seers (IFR)

unread,
Jan 19, 2009, 7:23:17 AM1/19/09
to r-h...@r-project.org

Hi All


How can you associate names with a list when names have not been
assigned? For example if you have a list like this:


list2<-list(1,2,3)
list2

[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3


How do you make it look like this with names? :

f1<-1
f2<-2
f3<-3
list1<-list(name1=f1, name2=f2, name3=f3)
list1
$name1
[1] 1

$name2
[1] 2

$name3
[1] 3

Thanks for any help.

I expect there is a simple answer but I cannot find it ...


Regards

John

---

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

unread,
Jan 19, 2009, 7:29:45 AM1/19/09
to john seers (IFR), r-h...@r-project.org
If I understand correctly:

names(list2) <- paste("name", 1:3, sep = "")

On Mon, Jan 19, 2009 at 10:23 AM, john seers (IFR)
<john....@bbsrc.ac.uk>wrote:

--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

john seers (IFR)

unread,
Jan 19, 2009, 8:26:08 AM1/19/09
to Henrique Dallazuanna, r-h...@r-project.org

Thanks Henrique and Nathalie for your answers.

Very strange - I thought I had tried that and it had not worked so I came to the conclusion that names did not work on lists. Now it does work, so I must have had some finger trouble.

Regards

John


---

mondher mehdi

unread,
Jan 20, 2009, 3:00:54 PM1/20/09
to john....@bbsrc.ac.uk, r-h...@r-project.org
Hi
for var names other than name1 ,2 and 3
for exple green yellow red use simply
names(list2)=c("green","yellow","red")

[[alternative HTML version deleted]]

Reply all
Reply to author
Forward
0 new messages