Re: [R] Calling a function to store values

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Thu, 03 Mar 2011 10:50:50 -0600

On Mar 3, 2011, at 10:12 AM, kparamas wrote:

> Hi,
>
> I am calling a function with different arguments to read different
> files and
> want the results to be stored in
> different matrices.
>
> Ex:
> cData1 = NULL
> cData2 = NULL
>
> readData = function(cData, start, end)
> {
>
> ....
> cData = //reads from the file
> }
>
> I am calling the functions using
> readData(cData1,1,3)
> readData(cData2,4,7)
>
> But After running the code, cData1 and cData2 are not getting updated.
> Is there a way in R to do this?
You need to assign the results of the function to an R object in the global environment. At the moment calling readData() only creates the cData object in the environment of the function which then disappears after function completion.

Try :

cdata_1_1_3 <- readData(cData1,1,3)
cdata_2_4_7 <- readData(cData2,4,7)

>
> --
> View this message in context: http://r.789695.n4.nabble.com/Calling-a-function-to-store-values-tp3333644p3333644.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



R-help_at_r-project.org 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 Thu 03 Mar 2011 - 17:44:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Mar 2011 - 22:50:18 GMT.

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

list of date sections of archive