使用自动生成的值更改R中的列名称

时间:2015-10-03 22:34:58

标签: r

好的,我是R的新手所以请保持温柔。我有一个通过API访问的数据集。它已包含描述性列名。但是,当我导入它时,列名默认为V1,V2,....数据的V18和第1行是实际的描述性列名{ID,Duration,Timestamp,...}。

如何让列名称成为描述性的,而不是这些显然是自动生成的V#?

1 个答案:

答案 0 :(得分:1)

根据您上面的评论和包含的字符串,您只需使用

即可
df <- read.csv(text = x)
head(names(df))
# [1] "id"               "duration"         "timestamp"        "gender"          
# [5] "totalFaceSeconds" "attention" 

其中x

x <- "\"id\",\"duration\",\"timestamp\",\"gender\",\"totalFaceSeconds\",\"attention\",\"engagement\",\"sentiment\",\"positive\",\"negative\",\"neutral\",\"anger\",\"contempt\",\"disgust\",\"fear\",\"joy\",\"sadness\",\"surprise\"\n\"29192c40-4f88-cf31-92c8-545004f10336\",\"30.0\",\"0\",\"FEMALE\",\"13\",\"1.0\",\"0.1960399144063954\",\"0.36114759724872375\",\"1.012803753260739\",\"1.7916002105934554\",\"10.195596036145806\",\"0.16218054983772182\",\"0.5519610232909892\",\"0.4580025835719351\",\"0.39209044064081255\",\"1.012803753260739\",\"0.2273656132519967\",\"0.0\"\n"