函数式编程
旧的离场-替代伎俩:a<-data.frame(x=1:10,y=1:10)test<-function(z){ mean.x<-mean(z$x) nm <-deparse(substitute(z)) print(nm) return(mean.x)} test(a)#[1] "a" ... this is the side-effect of the print() call# ... you could have done something useful with that character value#[1] 5.5 ... this is the result of the function call编辑:使用新的测试对象运行它。注意:当一组列表项从第一个参数传递到lapply(当对象从给定的列表中传递给for-循环如果结构结果是正在处理的命名向量,则可以从结构结果中提取“.names”-属性和处理顺序。> lapply( list(a=4,b=5), function(x) {nm <- deparse(substitute(x)); strsplit(nm, '\\[')} )$a$a[[1]][1] "X" "" "1L]]"$b$b[[1]][1] "X" "" "2L]]"> lapply( c(a=4,b=5), function(x) {nm <- deparse(substitute(x)); strsplit(nm, '\\[')} )$a$a[[1]][1] "structure(c(4, 5), .Names = c(\"a\", \"b\"))" "" [3] "1L]]" $b$b[[1]][1] "structure(c(4, 5), .Names = c(\"a\", \"b\"))" "" [3] "2L]]"