如何从dataframe中提取列名并将其与输入进行比较

如何从dataframe中提取列名并将其与输入进行比较,r,shiny,R,Shiny,我已经设置了textInput来输入操作需要考虑的列名。我想将其与dataframe中具有相同名称的现有列进行比较,以便在该列下的元素上进行处理。这就是您要尝试做的吗 #make some data x <- c(1,2,3) y <- c("a","b","c") #put it in a dataframe df <- data.frame(x,y) #put the name of a column in a variable and access the column

我已经设置了textInput来输入操作需要考虑的列名。我想将其与dataframe中具有相同名称的现有列进行比较,以便在该列下的元素上进行处理。

这就是您要尝试做的吗

#make some data
x <- c(1,2,3)
y <- c("a","b","c")
#put it in a dataframe
df <- data.frame(x,y)

#put the name of a column in a variable and access the column
textInput <- "x"
df[textInput]
  x
1 1
2 2
3 3
#put the name of a column in a variable and access the column
textInput <- "y"
df[textInput]
  y
1 a
2 b
3 c
#制作一些数据

请提供您已经拥有的代码,最好最小化为一个简单的示例,该示例可以被视为R的一般示例。说明预期行为以及您的代码如何偏离预期行为。