1

I create a list and I want to name the elements of the list. Could somebody help me on this?

LL <- vector(mode = "list")

L11 <- seq(1, 10)
L12 <- seq(11, 20)
LL[[length(LL)+1]] <- cbind(L11, L12)   
# I want to name LL[[1]] as "L1", but this does not work
names(LL[[length(LL)]]) <- c("L1")

L21 <- seq(21, 30)
L22 <- seq(31, 40)
LL[[length(LL)+1]] <- cbind(L21, L22)
# I want to name LL[[2]] as "L2", but this does not work
names(LL[[length(LL)]]) <- c("L2")

LL
Apostolos
  • 598
  • 1
  • 5
  • 13

2 Answers2

0

This should work

LL <- vector(mode = "list") 
LL$l1 <- seq(1, 10)
LL$l2 <- seq(11, 20)
David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Chirayu Chamoli
  • 2,076
  • 1
  • 17
  • 32
0

According to David Arenburg (see comment above):

names(LL)[1L] <- "L1"

See here to understand how it works.

Community
  • 1
  • 1
Apostolos
  • 598
  • 1
  • 5
  • 13