Skip to content

Help

3 messages · Francesca PANCOTTO, Joshua Wiley, Patrick Burns

#
Hi Francesca,

Try something like this:

x <- c(1, 3, 7)
dati <- lapply(1:4, function(i) {datiP[datiP$city == i, x]})

dati[[1]] # datiP1
dati[[2]] # datiP2
dati[[3]] # datiP3
dati[[4]] # datiP4

if the *only* groups are 1, 2, 3, 4 (i.e., 1:4 is exhaustive), this
can be simplified:


dati <- by(datiP, datiP$city, `[`, x)

For documentation, see:

?lapply
?by
?"[" # to see how I use the extraction operator as a function

Hope this helps,

Josh

On Fri, Nov 11, 2011 at 12:24 PM, Francesca
<francesca.pancotto at gmail.com> wrote:

  
    
#
You've been told how to do what you ask.
But I'm not convinced that you really
want to do what you asked.

It might be better to do whatever you
want with the data leaving it all in one
object.  There are many ways of doing that,
the 'by' function is one of them.
On 11/11/2011 20:24, Francesca wrote: