[R-sig-DB] Extracting a column of numbers from a data frame
Douglas Bates
b@te@ @end|ng |rom @t@t@w|@c@edu
Mon Feb 20 21:37:50 CET 2006
On 2/20/06, Jason Horn <jhorn using bu.edu> wrote:
> When using RMySQL to retrieve data from a database, the result is
> always a data frame. What is the best way to take get the numbers
> from a column of the data frame into a vector? That is, I just want
> the column of numbers from the data frame and not the column label.
> I'm sure this has been done many times, but I'm new to this, so I
> thought I'd ask.
You use the "[[" subscripting operator or its short form for use with
names, the $ operator.
If your data frame is called "df" and you want the third column as a vector use
df[[3]]
If the name of the column is "foo" you can also use
df[["foo"]]
The expression
df$foo
is syntactic sugar for df[["foo"]]
More information about the R-sig-DB
mailing list