(This article was first published on

**One Tip Per Day**, and kindly contributed to R-bloggers)This is a trivial but very useful tip:

> x=data.frame(a=1:4, c=5)

> x

a c

1 1 5

2 2 5

3 3 5

4 4 5

> x[1,]

a c

1 1 5

> x[,1]

[1] 1 2 3 4

> x[,1, drop=F]

a

1 1

2 2

3 3

4 4

where you can see that:

- to avoid a[, i] become a vector, rather than a single-column data frame, we can use drop=F option.

Here is full explanation for that:

http://stat.ethz.ch/R-manual/R-patched/library/base/html/Extract.data.frame.html

To

**leave a comment**for the author, please follow the link and comment on their blog:**One Tip Per Day**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...