Skip to content
Prev 59664 / 398502 Next

data.frame into vector

On Tue, 2004-11-23 at 16:27 +0000, Tiago R Magalhaes wrote:
Part of the problem that you are having, as you seem to pick up, is that
the first column in 'x' is a factor and you need to coerce it to a
character.

If you review the help for as.matrix, you will note in the details
section:

"as.matrix is a generic function. The method for data frames will
convert any non-numeric/complex column into a character vector using
format and so return a character matrix, except that all-logical data
frames will be coerced to a logical matrix."

Thus, one approach is:
a   b
"a" "4"

This coerces the data frame to a character matrix, which is then
subsetted to the first row only.

HTH,

Marc Schwartz