select a column in data frame in r

To select a column in a data frame in R, you can use the subset() function or index the column using square brackets. Here's an example using the built-in mtcars data frame:

main.r
# Using subset()
subset(mtcars, select = mpg)

# Using square brackets
mtcars[, "mpg"]
87 chars
6 lines

Both of these methods will return a vector containing the values in the specified column. You can also use the $ operator to select a column by name:

main.r
mtcars$mpg
11 chars
2 lines

gistlibby LogSnag