[R] How to append the random no.s for different variables in the same data.frame
PIKAL Petr
petr.pikal at precheza.cz
Wed Sep 12 11:01:39 CEST 2012
Hi
This is the error I get with your code and this prevents us to give you reasonable help.
Error in eval.quoted(.variables, data) : object 'My_data' not found
Petr
> -----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 9:36 AM
> To: R. Michael Weylandt
> Cc: r-help at r-project.org
> Subject: Re: [R] How to append the random no.s for different variables
> in the same data.frame
>
> Dear Mr Weylandt and R helpers,
>
> Thanks a lot for your suggestion. Unfortunately the "return" statement
> in my original R code returns me different results which are obtained
> after processing the function I have constructed.
>
> My requirement for storing the product-wise random numbers is just a
> part of my whole exercise. For each of the products, I generate a set
> of random no.s, process these, construct some statistics and obtain
> these statistics using the "Return" statement. So for each of the
> products, I get these set of statistics generated and that is not my
> problem.
>
> My problem is "BESIDES getting my required output (which anyways I am
> getting)", I need the product-wise random numbers I have already
> generated and store them together in a single data.frame. So a single
> data.frame gives me all the product wise random nos.
>
> I am reproducing my problem once again -
>
> # ____________________________________
>
>
> 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
>
> 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
>
> product random no
> product1 .......
> product1
> .......
> .............................
>
> product1 ....... # (There will be 100 such
> values for product1)
> product2 .......
> product2 .......
>
> ............................
> ............................
> product12 ......
> ............................
> product12 .......
>
>
> Thanking you in advance
>
> Vincy
>
>
> [[alternative HTML version deleted]]
More information about the R-help
mailing list