[R] selection of multiple subscripts

Duncan Murdoch murdoch at stats.uwo.ca
Wed Jan 13 15:02:54 CET 2010


On 13/01/2010 8:09 AM, e-letter wrote:
> On 13/01/2010, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> > On 13/01/2010 7:36 AM, e-letter wrote:
> >> Readers,
> >>
> >> For a data set 'x':
> >>
> >> 1 a
> >> 2 b
> >> 3 c
> >> 4 d
> >> 5 e
> >> 6 f
> >> 7 g
> >> 8 h
> >> 9 i
> >>
> >> How to select multiple subscripts to plot? For example to plot values
> >> 1:3 and 9:10:
> >>
> >> plot(x[1:3,1],x[,2])
> >>
> >> and
> >>
> >> plot(x[9:10,1],x[,2])
> >>
> >> into one plot?
> >
> > Neither of those will work, because your x[,2] vector is longer than the
> > other vector.
> >
> > What you want is something like this:
> >
> > plot(col2 ~ col1, data=x[c(1:3, 9:10),])
> >
> Thanks, I now understand the concatenate function would help but
> forgot the syntax. Anyway I've just realised that the search database
> for R yields no result for '?concatenate' which is surprising.

That's because there's no "concatenate" function in base R.  If you want 
to search for the word "concatenate", use "??concatenate".  You won't 
find the c() function, because it is called "combine", but you'll find 
several other ways to concatenate.

Duncan Murdoch



More information about the R-help mailing list