Dear Sir,

Thanks for your reply. Sir, the function I have defined (i.e. addition) was just an indicative one. The function I have actually constructed is bit complex. Basically, I wish to learn how the same function can be applied to a dataframe where each row of the dataframe becomes new input and the function returns me new output. Here from example point of view, my outputs are 30, 70 and 14.

However, the function which I have created is generating an output having 1000 records pertaining to each row (i.e. new input) of the dataframe I am using actually.

Thanks again Sir, for the guidance. I hope the command which you have provided me for writing the output in csv form, may be useful. Only thing is that if in my dataframe, I have 5 input set, I need to get 5 different csv files.

Regards

Amelia

--- On Wed, 15/12/10, Seeliger.Curt@epamail.epa.gov <Seeliger.Curt@epamail.epa.gov> wrote:

From: Seeliger.Curt@epamail.epa.gov <Seeliger.Curt@epamail.epa.gov>
Subject: Re: [R] Applying function to a TABLE and also "apply, tapply, sapply etc"
To: r-help@r-project.org
Received: Wednesday, 15 December, 2010, 4:47 PM

Amelia of Aukland writes:
> Suppose instead of having above dataframe having single data for 
> variable 1 and variable 2, I have following data as
> 
> variable_1           variable_2
> 
>        10                         20
>         40                         30 
>         3                          11

And so you do:
foo <- data.frame(variable_1=c(10,40,3), variable_2=c(20,30,11))

> I need to run the function 'fun' for each pair of values taken by 
> variable_1 and variable_2 separately. Also, the results (= 30, 70 
> and 14) obtained for each of above pairs should be stored in 
> different csv files, say "ans1.csv", "ans2.csv" and "ans3.csv" 
> respectively which I can use for further analysis. (In reality each 
> of these output files will consists of 1000 records).

No function is necessary, though apply() would work as has been pointed 
out.
foo$answer <- foo$variable_1 + foo$variable_2

Writing to a csv is another matter--
write.csv(foo, 'foo.csv')


-- 
Curt Seeliger, Data Ranger
Raytheon Information Services - Contractor to ORD
seeliger.curt@epa.gov
541/754-4638



    [[alternative HTML version deleted]]

______________________________________________
R-help@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.



      
	[[alternative HTML version deleted]]

