R: specifying variable name in function parameter for a function of general (universal) use

后端 未结 3 650
慢半拍i
慢半拍i 2021-01-01 05:23

Here is my small function and data. Please note that I want to design a function not personal use for general use.

dataf <- data.frame (A= 1:10, B= 21:         


        
3条回答
  •  Happy的楠姐
    2021-01-01 05:42

    You could always go the (horrors) parse() route:

    Rgames: foo<- data.frame(one=1:5,two=6:10)
    Rgames: bar <- function(y) eval(parse(text=paste('foo$',y,sep='')))  
    

    Which is to say, inside your function, grab the arguments to the function and build up the internal data frame or pairs of vectors of data you want using the eval(parse(...)) setup.

提交回复
热议问题