-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of Vincy Pyne
Sent: Wednesday, September 12, 2012 8:51 AM
To: r-help at r-project.org
Subject: [R] How to append the random no.s for different variables in
the same data.frame
Dear R helpers,
(At the outset I sincerely apologize if I have not put forward my
following query properly, though I have tried to do so.)
Following is a curtailed part of my R - code where I am trying to
generate say 100 random no.s for each of the products under
consideration.
library(plyr)
n = 100
my_code = function(product, output_avg, output_stdev)
??? {
BUR_mc = rnorm(n, output_avg, output_stdev)
sim_BUR = data.frame(product, BUR_mc)
write.csv(data.frame(sim_BUR), 'sim_BUR.csv', row.names = FALSE)
return(list(output_avg, output_stdev))
??? }
result <- dlply(.data = My_data, .variables = "product", .fun =
function(x)
???????????????? my_code(product = x$product, output_avg =
x$output_avg,
???????????????? output_stdev = x$output_stdev))
There are some 12 products (and this may vary each time). In my
original code, the "return" statement returns me some other output.
Here for simplicity sake, I am just using the values as given in input.
PROBLEM - A :
I want to store the random no.s (BUR_mc) as generated above for each of
the products and store them in a single data.frame. Now when I access
'sim_BUR.csv', I get the csv file where the random nos. generated for
the last product are getting stored. I need something like