Converting two columns of a data frame to a named vector

后端 未结 6 1102
無奈伤痛
無奈伤痛 2020-11-29 06:31

I need to convert a multi-row two-column data.frame to a named character vector. My data.frame would be something like:

dd = data.         


        
6条回答
  •  清酒与你
    2020-11-29 06:52

    Here is a very general, easy way. Presently, it works with the development version of dplyr available via github

    # devtools::install_github("tidyverse/dplyr") # dplyr_0.8.99.9003
    
    # .rs.restartR() # Restart R session if dplyr was loaded before
    library(dplyr)
    
    iris %>%
      pull(Sepal.Length, Species)
    
    

    (the first argument is the values, the second argument is the names)

提交回复
热议问题