【发布时间】:2017-03-16 18:23:35
【问题描述】:
在我的 Excel 文档中,我使用的列是“通信模式”,该列中的条目使用空格“亲自”或斜杠“IM/Chat”。
这些不断抛出错误:
- eval 中的错误(expr、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/Chat 来克服“/”?我尝试将它在 excel 表中的显示方式更改为“In_Person”和“Chat”,这导致了同样的错误。我会继续胡闹,但欢迎任何建议。如果我找到解决方案,我一定会发布解决方案。
谢谢
不好意思,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中使用