Body: <p>I have a data frame columns are pathways and genes are rows</p>
  <p>Like</p>
  <pre class="lang-r prettyprint-override"><code>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:
   <span class="math-container">$ Release.of.Cancer.Cell.Antigens: chr  "ARID1A" "ATM"
   $</span> Cancer.Antigen.Presentation    : chr  &quot;ARG2&quot; &quot;ATF3&quot;
  </code></pre>
  <p>I want to make a list of pathways containing their genes, something like</p>
  <pre class="lang-r prettyprint-override"><code>str(h.sets)
  List of 50
   $ HALLMARK_ADIPOGENESIS                     : chr [1:208] &quot;ABCA1&quot; &quot;ABCB8&quot; &quot;ACAA2&quot; &quot;ACADL&quot; ...
   $ HALLMARK_ALLOGRAFT_REJECTION              : chr [1:332] &quot;AARS1&quot; &quot;ABCE1&quot; &quot;ABI1&quot; &quot;ACHE&quot; ...
  </code></pre>
  <p>I done so</p>
  <pre class="lang-r prettyprint-override"><code>h.names &lt;- unique(colnames(a))
  h.sets &lt;- vector(&quot;list&quot;,length=length(h.names))
  names(h.sets) &lt;- h.names
  </code></pre>
  <p>But here I get error here</p>
  <pre class="lang-r prettyprint-override"><code>for (i in names(h.sets)) {
      h.sets[[i]] &lt;- 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.
  </code></pre>
  <p>Any help please</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-30T19:35:49.383Z
Comments.Text: 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.
Comments.UserDisplayName: Cloudberry
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-30T19:46:53.610Z
Comments.Text: Why are you using `pull`? Why not a simple `h.sets[[i]] <- a[i]`?
Comments.UserDisplayName: Ram RS
Tags: <r><pathway><gsea>
Title: Making a list of lists in R
ThreadText: # Making a list of lists in R
  
  (Asked by: username_0 on 2023-05-30)
  
  I have a data frame columns are pathways and genes are rows
  
  Like
  
  ```r
  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
  
  ```r
  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
  
  ```r
  h.names <- unique(colnames(a))
  h.sets <- vector("list",length=length(h.names))
  names(h.sets) <- h.names
  
  ```
  
  But here I get error here
  
  ```r
  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
  
  **Tags:** r, pathway, gsea
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_2**: Why are you using `pull`? Why not a simple `h.sets[[i]] <- a[i]`?  
  
  ---
  
  ## 0 answers
  
  