Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would suggest not using <code>attach</code> in general</p> <p>If you are just trying to get columns from <code>mydata</code> you can use <code>[</code> to index the list</p> <pre><code>aggregate(mydata, by = mydata[keynn], FUN = length) </code></pre> <p>should work -- and is very clear that you want to get <code>keynn</code> from <code>mydata</code></p> <p>The problem with using <code>attach</code> is that it adds <code>mydata</code> to the search path (not copying to the global environment)</p> <p>try</p> <pre><code> attach(mydata) mget(keynn, .GlobalEnv) </code></pre> <p>so if you were to use <code>mget</code> and <code>attach</code>, you need</p> <pre><code> mget(keynn, .GlobalEnv, inherits = TRUE) </code></pre> <p>so that it will not just search in the global environment.</p> <p>But that is more effort than it is worth (IMHO)</p> <p>The reason <code>get</code> works is that <code>inherits = TRUE</code> by default. You could thus use <code>lapply(keynn, get)</code> if <code>mydata</code> were attached, but again this ugly and unclear about what it is doing.</p> <hr> <p>another approach would be to use <code>data.table</code>, which will evaluate the <code>by</code> argument within the data.table in question</p> <pre><code> library(data.table) DT &lt;- data.table(mydata) DT[, {what you want to aggregate} , by =keynn] </code></pre> <p>Note that keynn doesn't need to be a character vector of names, it can be a list of names or a named list of functions of names etc</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload