我有一个矩阵,我想消除两列的名称。 我的代码是:
az container create --resource-group demors --name demoaci --image demoacr.azurecr.io/hello-world:v1 --cpu 1 --memory 1 --registry-login-server demoacr.azurecr.io --registry-username demoacr --registry-password ThePassword --dns-name-label demo3 --ports 80
但是R给我这样的错误消息:
trn_data = subset(trn_data, select = -c("Rye flour","Barley products"))
我尝试过
Error in -c("Rye flour", "Barley products") :
invalid argument to unary operator
还返回错误:
trn_data = subset(trn_data, select = -c(Rye flour,Barley products))
我该如何解决?还有其他方法可以消除两列的名称吗?
答案 0 :(得分:1)
您不应提供从Listening on http://127.0.0.1:7723
Error in staticPath(path) : `path` must be a non-empty string.
到characters
的名称。这有效:
subset
如果列名中有空格,则应使用 Grave Accent 。
下面是使用trn_data_subset <- subset(trn_data, select = -c(`Rye flour`,`Barley products`))
数据集的示例:
mtcars
您也可以像这样:
mtexapmple <- mtcars[1:4,]
names(mtexapmple)[1] <- "mpg with space"
mtexapmple
#> mpg with space cyl disp hp drat wt qsec vs am gear carb
#> Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
#> Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
#> Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
#> Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
subset(mtexapmple, select = -c(`mpg with space`, `cyl`))
#> disp hp drat wt qsec vs am gear carb
#> Mazda RX4 160 110 3.90 2.620 16.46 0 1 4 4
#> Mazda RX4 Wag 160 110 3.90 2.875 17.02 0 1 4 4
#> Datsun 710 108 93 3.85 2.320 18.61 1 1 4 1
#> Hornet 4 Drive 258 110 3.08 3.215 19.44 1 0 3 1
或
within(trn_data, rm(`Rye flour`,`Barley products`))
答案 1 :(得分:1)
使用dplyr
,我们仍然可以使用双引号-
library(dplyr)
mtexample %>%
select(-"mpg with space")
# cyl disp hp drat wt qsec vs am gear carb
#Mazda RX4 6 160 110 3.90 2.620 16.46 0 1 4 4
#Mazda RX4 Wag 6 160 110 3.90 2.875 17.02 0 1 4 4
#Datsun 710 4 108 93 3.85 2.320 18.61 1 1 4 1
#Hornet 4 Drive 6 258 110 3.08 3.215 19.44 1 0 3 1
mtexample <- mtcars[1:4,]
names(mtexample)[1] <- "mpg with space"