Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

While making a list of objectives, is there a way of retaining the object symbols to use them as names on the list?

The below uses to get and re-assigns names afterward, and I wondered if there is another approach.

a_1 <- 1

a_2 <- 2

a_3 <- 3

ls_a <-  lapply(ls(pattern = "a_"), get)

names(ls_a) <- ls(pattern = "a_")

ls_a

#> $a_1

#> [1] 1

#> 

#> $a_2

#> [1] 2

#> 

#> $a_3

#> [1] 3

1 Answer

0 votes
by (108k points)

As far as I know that in R programming, the mget has this as a default behavior.

mget(ls(pattern = "a_"))

#$a_1

#[1] 1

#$a_2

#[1] 2

#$a_3

#[1] 3

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...