Skip to content
Prev 327312 / 398502 Next

flexible approach to subsetting data

On Jul 23, 2013, at 2:00 PM, David Carlson wrote:

            
That's really elegant and much more "elastic". (I hadn't realized that a logical vector would be accepted.) Also possible to just use 'grep' which would instead construct a vector of column numbers as the list elements of 'varying'. I've wondered for years whether the help page description of 'varying could be improved. It currently says:

"varying : 
names of sets of variables in the wide format that correspond to single variables in long format (?time-varying?). This is canonically a list of vectors of variable names, but it can optionally be a matrix of names, or a single vector of names. In each case, the names can be replaced by indices which are interpreted as referring to names(data). See ?Details? for more details and options."

I wondered if it might say instead:

"a list of sets of variables in the wide format that each correspond to single variables in long format (?time-varying?). This is canonically a list of vectors of column names or numbers , but it can optionally be a matrix of names, or a single vector of names. In each case, the names can be replaced by numeric or logical indices which are interpreted as extracting from names(data). See ?Details? for more details and options."

But it supposedly is the case that it can be a set of names, and in that case there is also a  further promise that an effort to do the automagic splitting. Unfortunately the magic is often unsuccessful
+ 	varying=c("dose", "resp")
+      )
Error in guess(varying) : 
  failed to guess time-varying variables from their names

# Seems like it should have been possible:
dose.0 resp.0 dose.1 resp.1 dose.2 resp.2 dose.3 resp.3
1     40     40      1      4      2      4      3      4
2     50     50      2      5      1      5      3      5
3     60     60      1      4      2      4      3      4
4     50     50      2      5      1      5      3      5