R 如何使用字符更改标签?
我读过csv文件R 如何使用字符更改标签?,r,label,R,Label,我读过csv文件 X Date Price.Dollars.per.Thousand.Cubic.Feet 1 0 2002-01-15 3.10 2 1 2002-02-15 2.86 3 2 2002-03-15 3.37 4 3 2002-04
X Date Price.Dollars.per.Thousand.Cubic.Feet
1 0 2002-01-15 3.10
2 1 2002-02-15 2.86
3 2 2002-03-15 3.37
4 3 2002-04-15 3.80
5 4 2002-05-15 3.78
6 5 2002-06-15 3.61
7 6 2002-07-15 3.49
我想使用ggplot2进行绘图。
这个很好用
piz$Date = as.Date(piz$Date)
但是当我尝试的时候
piz$prices = as.character( Price Dollars per Thousand Cubic Feet)
我有问题
Error: unexpected symbol in "piz$prices = as.character( Price Dollars"
这也不行
piz$prices = as.character(piz$ Price Dollars per Thousand Cubic Feet)
为什么?因为R已将列名中的空格替换为“.”。以下几点应该行得通
piz$prices = as.character(piz$Price.Dollars.per.Thousand.Cubic.Feet)
您必须使用“.”代替“”:
piz$价格
piz$prices<- as.character(piz$"Price.Dollars.per.Thousand.Cubic.Feet")