Converting two columns of a data frame to a named vector

Use the names function:

whatyouwant <- as.character(dd$name)
names(whatyouwant) <- dd$crit

as.character is necessary, because data.frame and read.table turn characters into factors with default settings.

If you want a one-liner:

whatyouwant <- setNames(as.character(dd$name), dd$crit)

Leave a Comment