[R] character vector as input to function?

Ben Bolker ben at eno.princeton.edu
Wed Apr 14 15:09:37 CEST 1999


  Well, somebody else will probably respond, but for example:

paca:ben> cat >~/R/test
1 2 3 4

> doit <- function(filename) {
+    path <- "~/R/"  
+    x <- scan(paste(path,filename,sep=""))
+    mean(x)
+ }
> doit("test")
Read 4 items
[1] 2.5


On Wed, 14 Apr 1999, Bill Simpson wrote:

> I would like to have a function that inputs a file name, then reads that
> data file and does various stuff to it.
> Something like:
> 
> doit<-function(filename)        
> {
> x<-scan("~/rstuff/data/"filename)
> #for example, if filename is a0.dat, it will scan("~/rstuff/data/a0.dat")  
> ...
> }
> 
> Can someone please tell me how to do this?
> 
> Thanks for any help!
> 
> Bill Simpson
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._.._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

Benjamin Bolker          Dep't of Ecology and Evolutionary Biology,
ben at eno.princeton.edu    Princeton University
tel: (609) 258-6886,     fax: (609) 258-1334

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list