Using syntactically difficult strings as column names in a data frame

后端 未结 2 1217
天涯浪人
天涯浪人 2021-01-26 03:05

I\'m working with a data frame similar to the extract below:

df <- data.frame(A=c(\"Some messy string to be used\",222,0), 
                 B=c(\"Very import         


        
2条回答
  •  有刺的猬
    2021-01-26 03:50

    You don’t need to use make.names at all — you can assign the strings directly. This works perfectly fine in R. You just need to backtick-quote the names when you try to use them as R names (e.g. after the $ operator):

    names(df) = unlist(df[1,])
    df$`Some messy string to be used`
    

提交回复
热议问题