如何在带“。”的data.frame列上使用mutate()作为列名?

时间:2019-06-24 15:23:12

标签: r dplyr

示例数据帧如下:

df <- structure(list(. = c(0.00317362115369602, 0.505438165459309, 
-0.50869620206541, -0.0235439732192338, -0.519977844380413, -0.538712745887805, 
0.000183556453048905, 0.13963792646916, 0.551730393685303, -0.000455169630885266, 
0.519847490260643, 0.568301455381374, -0.00733858665553655, -0.497276666052158, 
-0.558024223311325, 1.11137539325724, -0.51090025465732, -0.502518125766347, 
-0.525916664339648, -0.531254672991939)), row.names = c("100_g_at", 
"1000_at", "1001_at", "1002_f_at", "1003_s_at", "1004_at", "1005_at", 
"1006_at", "1007_s_at", "1008_f_at", "1009_at", "101_at", "1010_at", 
"1011_s_at", "1012_at", "1013_at", "1014_at", "1015_s_at", "1016_s_at", 
"1017_at"), class = "data.frame")

如果我使用df %>% mutate(NewColName = "."),它将带有“。”从字面上看是一个字符串值。用户@joran指出df %>% rename(NewColName = ".")可以正常工作。

我以某种方式想出了以下代码是否有效,如果只有一列名称为“。”的列:

df %>% mutate(NewColName = .[])

但是我不明白.[]是什么意思?为什么rename有效但mutate无效?

0 个答案:

没有答案