Stack Exchange
Making a list of lists in R
I have a data frame columns are pathways and genes are rows
Like
head(a[1:2,1:2])
  Release.of.Cancer.Cell.Antigens Cancer.Antigen.Presentation
1                          ARID1A                        ARG2
2                             ATM                        ATF3

str(a[1:2,1:2])
'data.frame':   2 obs. of  2 variables:
 $ Release.of.Cancer.Cell.Antigens: chr  "ARID1A" "ATM"
 $ Cancer.Antigen.Presentation    : chr  "ARG2" "ATF3"

I want to make a list of pathways containing their genes, something like
str(h.sets)
List of 50
 $ HALLMARK_ADIPOGENESIS                     : chr [1:208] "ABCA1" "ABCB8" "ACAA2" "ACADL" ...
 $ HALLMARK_ALLOGRAFT_REJECTION              : chr [1:332] "AARS1" "ABCE1" "ABI1" "ACHE" ...

I done so
h.names <- unique(colnames(a))
h.sets <- vector("list",length=length(h.names))
names(h.sets) <- h.names

But here I get error here
for (i in names(h.sets)) {
    h.sets[[i]] <- pull(a[colnames(a)==i])
}

Error in `pull()`:
! Can't extract columns past the end.
ℹ Location 1 doesn't exist.
ℹ There are only 0 columns.
Run `rlang::last_trace()` to see where the error occurred.

Any help please

Data frame is a type of list, so for most purposes you already have what you're asking. You can convert it into an ordinary list with as.list(a). If that doesn't help, you should tell more about what you're trying to achieve.

Why are you using pull? Why not a simple h.sets[[i]] <- a[i]?
