Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用奇怪的名称定义/调用对象?_R - Fatal编程技术网

R 使用奇怪的名称定义/调用对象?

R 使用奇怪的名称定义/调用对象?,r,R,我正要问另一个问题,所以这个问题突然出现在我的脑海里。我们如何用一个奇怪的名字定义一个对象。例如,假设我们想调用一个对象“test^#”。如果我想定义它,我会使用“”: “test^#”使用反勾号: "test^#" <- 10 ls() [1] "test^#" 还可以使用反勾号引用数据框(或列表)中具有非标准名称的列。例如: iris$`Sepal length` <- iris$Sepal.Length str(iris) 'data.frame': 150 obs.

我正要问另一个问题,所以这个问题突然出现在我的脑海里。我们如何用一个奇怪的名字定义一个对象。例如,假设我们想调用一个对象“test^#”。如果我想定义它,我会使用“”:

“test^#”使用反勾号:

"test^#" <- 10
ls()
[1] "test^#"

还可以使用反勾号引用数据框(或列表)中具有非标准名称的列。例如:

iris$`Sepal length` <- iris$Sepal.Length
str(iris)
'data.frame':   150 obs. of  6 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Sepal length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...


summary(iris$`Sepal length`)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  4.300   5.100   5.800   5.843   6.400   7.900 

太好了。谢谢@Andrie.Does
test\^\\\\\\\\\\\\\\#@CarlWitthoft使用转义序列检索对象时,我找不到任何变化。
`test^#`
[1] 10
iris$`Sepal length` <- iris$Sepal.Length
str(iris)
'data.frame':   150 obs. of  6 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Sepal length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...


summary(iris$`Sepal length`)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  4.300   5.100   5.800   5.843   6.400   7.900 
"test^`#" <- 20

get("test^`#")
[1] 20