This is a basic R question, not really pertinent to Bioconductor. In the future you should probably ask this sort of thing on the R-help listserv (r-help@r-project.org). Or better yet, just google it. You could just paste that error into Google's search bar and you would almost surely get an answer.
Another alternative is to look at the error and try to determine what it is telling you. These things are intended to be useful, rather than cryptic, so whomever wrote that error message intended that it would be self-explanatory. And really, it is. It says 'undefined columns selected'. You are trying to select columns from data1 based on whatever is in data2. If data2 contains anything that doesn't exactly match one of the columns in data1, you will get that error:
> data1 <- data.frame(a = 1:4, b = 2:5, c = 3:6)
> data2 <- data.frame(whatevs = letters[1:3])
> data2[,1]
[1] a b c
Levels: a b c
> data1[,data2[,1]]
a b c
1 1 2 3
2 2 3 4
3 3 4 5
4 4 5 6
> data2 <- data.frame(whatevs = letters[1:4])
> data1[,data2[,1]]
Error in `[.data.frame`(data1, , data2[, 1]) : undefined columns selected