There is a dataframe (x) with large number of columns. I want to select columns from it inside a function.
selectcols<-function(dat,xvar,yvar){
t<-dat[,c(xvar,yvar)]
}
selectcols(dat=x,xvar = "area",yvar = "y")
Here y and area are two columns. But this is not working. How can I fix it?
df <-data.frame(a=1:5,b=6:10,c=40:44).df[,c("a","c")]selectcols <- function(d,jx,jy) "["(d,c(jx,jy))torreturn(t). That should to the job.