Dear Maithili,

Here are two suggestions:

# data set
x <- read.table(textConnection("Name no_of_instances
AAA   12
AA    17
A      0
BBB   11
BB     6
B      0
C      8
D      3"), header = TRUE)
closeAllConnections()
x

# option 1
do.call(c,with(x, tapply(no_of_instances, Name, runif)))

# option 2
with(x, runif( sum(no_of_instances) ))

HTH,
Jorge

On Tue, Dec 15, 2009 at 8:26 AM, Maithili Shiva <> wrote:

> Dear R helpers
>
> I have following table
>
> Name                 no_of_instances
> AAA                             12
> AA                               17
> A                                  0
> BBB                             11
> BB                                6
> B                                  0
> C                                  8
> D                                  3
>
> Now I need to generate the uniform random numbers (against the no. of
> instances) and assign these numbers generated against the respective names.
> E.g. I need to generate 12 random numbers and assign these numbers against
> AAA.
>
> Individually I can generate them as
>
> AAA_no = c(runif(12))
> AA_no  = c(runif(17))
> ......
>
> and so on.
>
> And in the end I can club them as
>
> ran_nos = c(AAA_no, AA_no, ..........D_no)
>
> My problem is if there are say 1000  names, then it will be a cumbersome
> job to generate 1000 individual random number sets and then to combine them
> to form a single dataset.
>
> Is there any alternative to this?
>
> Thanking in advance
>
> With regards
>
> Maithili
>
>
>
>
>      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
>        [[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]]

______________________________________________
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.

Reply via email to