R函数不';我不能做我想做的事
我不明白为什么我的函数不起作用,你能帮我找到我的错误吗R函数不';我不能做我想做的事,r,R,我不明白为什么我的函数不起作用,你能帮我找到我的错误吗 VehiculeFunction <- function(data){ my.data <- data[data$GAMME =="M1",] ma.col = rgb(red = 0.1,blue = 1,green = 0.1, alpha = 0.2) X <- my.data$GMF.24 Y <- my.data$Cout.24 X11() plot(X, Y, pch=20, la
VehiculeFunction <- function(data){
my.data <- data[data$GAMME =="M1",]
ma.col = rgb(red = 0.1,blue = 1,green = 0.1, alpha = 0.2)
X <- my.data$GMF.24
Y <- my.data$Cout.24
X11()
plot(X, Y, pch=20, las = 1, col = ma.col, xlim = c(0, 10), ylim = c(0,10))
identify(X, Y, labels = my.data$NITG, cex = 0.7)
}
vehicleulefunction尝试以下操作。在这种情况下,您不能使用$运算符访问my.data
列(或列表元素),您需要为x
和y
传递字符串:
VehiculeFunction <- function(data, x, y, gamme){
my.data <- data[data$GAMME == gamme,]
ma.col = rgb(red = 0.1,blue = 1,green = 0.1, alpha = 0.2)
X <- my.data[[x]] # <- change from $ to [[]]
Y <- my.data[[y]] # <- change from $ to [[]]
X11()
plot(X, Y, pch=20, las = 1, col = ma.col, xlim = c(0, 10), ylim = c(0,10))
identify(X, Y, labels = my.data$NITG, cex = 0.7)
}
VehiculeFunction(data.vehicule, "GMF.24", "Cout.24", "M1") # <- change to strings
车辆功能数据是一个数据帧!请提供一个可复制的示例。此外,将x
和y
作为字符传递,并使用[/code>而不是$
来选择列。还有一个问题,我想添加一个“gamme”变量my.data谢谢Oleg,如果我想在我的数据帧的另一个变量上添加一个条件,我想使用“RANG\u NITG\u PROJET\K”中的所有三个my.data1尝试类似于df[df$COL%in%c(1,2,3),]
my.data1 <- my.data[my.data$RANG_NITG_PROJET_K == 1|2|3,] ?
my.data1 <- data.vehicule[data.vehicule$RANG_NITG_PROJET_K == 1,]
my.data2 <- data.vehicule[data.vehicule$RANG_NITG_PROJET_K == 2,]
my.data3 <- data.vehicule[data.vehicule$RANG_NITG_PROJET_K == 3,]
my.data <- rbind(my.data1, my.data2, my.data3)
VehiculeFunction <- function(data, x, y, gamme){
my.data <- data[data$GAMME == gamme,]
ma.col = rgb(red = 0.1,blue = 1,green = 0.1, alpha = 0.2)
X <- my.data[[x]] # <- change from $ to [[]]
Y <- my.data[[y]] # <- change from $ to [[]]
X11()
plot(X, Y, pch=20, las = 1, col = ma.col, xlim = c(0, 10), ylim = c(0,10))
identify(X, Y, labels = my.data$NITG, cex = 0.7)
}
VehiculeFunction(data.vehicule, "GMF.24", "Cout.24", "M1") # <- change to strings