I have a dataframe as follows:
> df <- data.frame("A"=rnorm(26), "B"=rnorm(26),row.names=sample(letters,26))
I then want to take column B out as a vector using a different row order
> newOrder <- sample(letters,26)
> vec <- df[newOrder,"B"] #1
How can I retain the correct rownames of df as the vector names of vec in a single statement at #1? That is, without having to do:
> names(vec) <- newOrder
You can set the names at the same time by using
setNames