Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In R how to operate in a list with names

This is my list

list_names <- vector(mode = 'list')

list_names[['NAME A']] <- rnorm(n = 10,sd = 2)
list_names[['NAME B']] <- rnorm(n = 10,sd = 2)
list_names[['NAME C']] <- rnorm(n = 10,sd = 2)
list_names[['NAME D']] <- rnorm(n = 10,sd = 2)
list_names[['NAME E']] <- rnorm(n = 10,sd = 2)
list_names[['NAME F']] <- rnorm(n = 10,sd = 2)

Is it possible to select others elements of list doing something like this:

list_names[[-"NAME A"]]

The output should be a list with all elements except the "NAME A" element?

like image 847
JohnBones JohnBones Avatar asked Oct 12 '25 09:10

JohnBones JohnBones


1 Answers

Probably this is what you are after

list_names[-match('NAME A',names(list_names))]

!! WARNING: if the requested name is not a valid name of list_names, then the solution will return NULL (thanks for @akrun's comment)

like image 59
ThomasIsCoding Avatar answered Oct 13 '25 23:10

ThomasIsCoding