Use df[1,,drop=FALSE] if you want the output to be a data.frame, no matter how many columns df has.
The effective default value for drop is TRUE if the output has a single column. This does not depend on whether or not you subscripted rows or columns or both. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of James Hirschorn > Sent: Sunday, November 14, 2010 4:32 PM > To: R-help@r-project.org > Subject: [R] Extracting from data.frame > > Can someone please explain the following behavior? > > > > df1 and df2 are data.frames. Suppose I want a subset of the rows > (observations) using extraction, say just the first row. What > I want to know > is why if df1 has just one column then df1[1,] returns a > vector, whereas if > df2 has 2 or more columns then df2[1,] returns a data frame? > Why is the > single column case different? > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.