##The example is:
xyTrain <- cbind(yTrain$V2, xTrain)
print(xyTrain)
## cannot change the name using the function below.
xyTrain <- rename(yTrain, yTrain$V2 = Activity)
##Error: unexpected '=' in "xyTrain <- rename(yTrain, yTrain$V2 ="
关于上面的错误:似乎问题出现'$'...它应该是一个字符,但它目前是一个运算符。我怎样才能改变它?
答案 0 :(得分:0)
我们可以使用backticks
来选择具有异常名称的变量。根据OP的例子,我们将'yTrain $ V2'改为'Activity'。在这种情况下,“活动”应位于lhs
的{{1}}。
=
能够使用OP的代码复制'错误'
dplyr::rename(yTrain, Activity = `yTrain$V2`)
# Activity
#1 WALKING_UPSTAIRS
#2 WALKING_UPSTAIRS
#3 WALKING_UPSTAIRS
dplyr::rename(yTrain, yTrain$V2 = Activity)
#Error: unexpected '=' in "dplyr::rename(yTrain, yTrain$V2 ="