如何eval解析其中包含空格的字符串
我创建了一个例子:
# Change the name of, the default in r available dataset, ChickWeight to get
# a variable with a space in it
`Chick Weight` <- ChickWeight
datasetnames <- c("iris", "cars", "Chick Weight")
head(eval(parse(text = datasetnames[1])))
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
head(eval(parse(text = datasetnames[2])))
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
head(eval(parse(text = datasetnames[3])))
Error in parse(text = datasetnames[3]) : <text>:1:7: unexpected symbol
1: Chick Weight
当我在eval(parse(text=))
功能中放置一个带有空格的字符串时,它会起作用。我怎么能这样做?
或者他们的另一种方法是从字符串中接近带有空格的可变障碍物?