I have a list:
alist <- list(x = c(1, 2, 3),
y = c(4, 5, 6))
> alist
$x
[1] 1 2 3
$y
[1] 4 5 6
I want to give names to each list component, to make it become:
> alist
$x
t1 t2 t3
1 2 3
$y
t1 t2 t3
4 5 6
I tried to use lapply():
lapply(alist, function(x) names(x) <- c("t1","t2","t3"))
but the output is:
$x
[1] "t1" "t2" "t3"
$y
[1] "t1" "t2" "t3"
What is wrong here? How can I use lapply correctly here? Because I have a rather big list.