subsetting data.frame without column names

What you want is a numeric vector instead of a data.frame. For this, you can just use as.numeric to do the conversion

> as.numeric(df[1,])
[1] 7.5 5.0 5.0 2.0 7.5 2.0 2.0 5.0

You can use unlist with option use.names=FALSE to return only vector without names.

unlist(test[1,], use.names=FALSE)
#[1] 7.5 5.0 5.0 2.0 7.5 2.0 2.0 5.0

test[1,] is still a data.frame with 8 columns. A data.frame can be regarded as a list having the same length for its list elements (or columns). So we can use unlist. This also works when you are creating a vector from more than one row.

unlist(test[1:2,], use.names=FALSE)

Or as @Frank suggested, if we are subsetting multiple rows by keeping the dimensions, we set the names to NULL and convert to matrix.

 as.matrix(setNames(test[1:2,],NULL))

Tags:

R