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> xX1 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
Ryan - Puzzling. My best guess is a misspelling or a truncation in the column name "intent" within latdata in the context of> unlikely <- latdata[latdata$intent %in% c(1,2,3,4),]but I do not see any such misspelling in your email. Could you try again, using some other way to specify the column on which you wish to subset ? Such as: figure out what number the column is (say it's the fifth column in latdata) and use> unlikely <- latdata[latdata[[5]] %in% c(1,2,3,4),]Otherwise, your R syntax looks fine to me. Try also asking> is.factor(latdata$intent)but I don't think that would have caused the error message you see. - tom blackwell - u michigan medical school - ann arbor - On Wed, 10 Sep 2003, Ryan Thomas Moore wrote:> 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
Can you cut the data.frame down to just 2 rows and 2 columns that display the error? You might find the error in the process of doing that. If not, you should be able to distribute your same question with an example so anyone else can reproduce the problem. This doesn't answer your question, but this technique can be used to resolve many difficult problems. spencer graves Ryan Thomas Moore wrote:> 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 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help