0
在我的excel文檔中,我使用的是「通信模式」,在該列中使用空格,「In Person」或斜線「IM /聊天」。R - 在變量和列名中帶空格和'/'的問題
這些不斷拋出的錯誤:
- 錯誤的eval(表達式,ENVIR,enclos):對象In.Person'未找到
- 同爲IM /聊天
我嘗試使用In.Person或IM.Chat,但他們提出錯誤。代碼是:
png(filename="Number of Interactions by Communication Mode.png")
person <- subset(desktracker, Mode.of.Communication="")
ByChat <- ggplot(subset(desktracker, IM.Chat!=""), aes(x=IM.Chat)) +
geom_bar() +
theme_bw() +
ylab("Number of Interactions") +
xlab("By Chat") +
theme(axis.title.y = element_text(color = "red"))
ByPerson <- ggplot(subset(person, In.Person =""), aes(x=In.Person)) +
geom_bar() +
theme_bw()+
ylab("Number of Interactions") +
xlab("In Person")
grid.arrange(ByChat, ByPerson, ByPhone, main="Number of Interactions by Communication Mode
for Reference 2016")
dev.off()
我是R的新手,並且在某人離開後接手了這個項目。到目前爲止,我試圖改變我在R中寫入「In Person」或「IM/Chat」的方式,以不同程度在「In.Person」或「IM.Chat」中取得成功。也許有一個通配符,我可以使用IM /聊天來克服'/'?我試着改變它在Excel表格中的顯示方式爲「In_Person」,只是「聊天」,導致了相同的錯誤。我會繼續亂搞,但會歡迎任何建議。如果我找到一個解決方案,我一定會發布解決方案。
感謝
對不起,desktracker是我用來打開數據集的變量:
setwd("Z:/DesktrackR/Ref_Semester")
file = "Desk_Tracker_flat_8-17-15_through_5-9-16.csv"
desktracker <- read.csv(file, sep=",")
了Excel的內容的想法
沒有至少約desktracker的內容的想法,這是不可能的回答。請記住,如果要避免這些問題,數據框中變量的名稱不應包含空格或點以外的特殊字符。 –
在句法上無效的變量名稱,例如帶空格或特殊符號的變量名稱,可以通過反引號''在ggplot2中使用。 – aosmith