[R] get() in sapply() in with()

From: Heinz Tuechler <tuechler_at_gmx.at>
Date: Thu 03 Aug 2006 - 23:45:19 EST

Dear All,

applying some function within a with() function I wanted to use also sapply() and get() to form a data.frame, but did not succede. Below is a simplified example.
It is possible to use sapply() within a with() function, it is also possible to use get() within a with() function, but when I try to use get within sapply within with I arrive at "Error in get(x, envir, mode, inherits) : variable "v5" was not found".
Is there a solution?

Heinz Tüchler

## example

df1 <- data.frame(v5=16:20, v6=21:25, v7=I(letters[16:20]), v8=letters[16:20])

with(df1, sapply(c('v5', 'v6'), get) ) ## Error, see next line
## Error in get(x, envir, mode, inherits) : variable "v5" was not found

with(df1, sapply(list(v5, v6), mean) ) # does work with(df1, get('v5') ) # does work

platform       i386-pc-mingw32                          
arch           i386                                     
os             mingw32                                  
system         i386, mingw32                            
status         Patched                                  
major          2                                        
minor          3.1                                      
year           2006                                     
month          07                                       
day            23                                       
svn rev        38687                                    
language       R                                        
version.string Version 2.3.1 Patched (2006-07-23 r38687)

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Aug 04 00:07:35 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 04 Aug 2006 - 02:18:13 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.