I have the following two data frames (the real data frames are much larger). I would like to determine at which position(s) both data frames contain a 3 (in this example spot [2,1] only).
a<-c(1,3,5)
b<-c(2,3,4)
c<-c(3,3,4)
d<-c(2,4,7)
e<-cbind(a,b)
f<-cbind(c,d)
colnames(e)<-c("a","b")
colnames(f)<-c("a","b")
Results:
e
## a b
## 1 2
## 3 3
## 5 4
f
## a b
## 3 2
## 3 4
## 4 7
I've tried to use the following function, but it doesn't work.
fun<-function(x)
{ifelse(e$x==3 & f$x==3, "yes","no")}
Vs<-c("a","b")
lapply(Vs, fun)
Does anyone have any ideas, specifically on how use a variable as the character after the extraction operator ($) in a user written function?