[R] dataframe subsetting

Ryan Thomas Moore rtmoore at fas.harvard.edu
Wed Sep 10 17:24:43 CEST 2003


I can create a small dataset, "x" below, and subset out rows based on 
values of a certain variable.  However, on the dataset I'm working on now, 
"latdata" below, I get a subscript error.  Any advice is appreciated!

Ryan


Successful:

> is.data.frame(x)
[1] TRUE
> x
  X1 X2 X3
1  1  3  5
2  2  4  6
> x[x$X2 %in% c(3),]
  X1 X2 X3
1  1  3  5

Unsuccessful:

> is.data.frame(latdata)
[1] TRUE
> is.numeric(latdata$intent)
[1] TRUE
> table(latdata$intent)

  1   2   3   4   5   6 
 34  23  67 179 996   2 
> unlikely <- latdata[latdata$intent %in% c(1,2,3,4),]
Error in x[[j]] : subscript out of bounds


------------------------------------------
Ryan T. Moore ~ Government & Social Policy
Ph.D. Candidate ~ Harvard University




More information about the R-help mailing list