3 回答
TA贡献1807条经验 获得超9个赞
旧的离场-替代伎俩:
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]]"
TA贡献1842条经验 获得超12个赞
deparse(quote(var))
- 3 回答
- 0 关注
- 782 浏览
添加回答
举报