We can use ==
exampledataframe$X2[exampledataframe$X1=="A"]
As a function
fun1 <- function(data, Var1, Var2, val){
data[[Var2]][data[[Var1]]==val]
}
fun1(exampledataframe, "X1", "X2", "B")
#[1] "4"
data
exampledataframe <- data.frame(X1= c("A", 1, "B", 2, "C"),
X2= c(3, "D", 4, "F", 5), stringsAsFactors=FALSE)
0
solved function that returns a value from column b when specifying a value from column a [closed]