Problem with data frame

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with data frame

Arun.stat
Dear r-users,

suppose I have n normal distributions with parameter N(0,i) i=1,2,.......,n
respectively.

Now I want to generate 500 random number for each distribution. And want to
put all 500*n random numbers
in a single data frame.

I tried with following code:

>n=20
random = data.frame(n)
for ( i in 2: length)
   {
    random[,i] = random(500,mean=0,sd=i)
   }

but while executing this I am getting errors.

Can anyone give me any suggestion?
Thanks and  regards
Arun

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Problem with data frame

Rich-32
Try this ...

> rDf <- data.frame(sapply(1:20, rnorm, n=500, mean=0))

Rich.

S & R Training & Consulting
mangosolutions
Tel    +44 1249 467 467
Fax   +44 1249 467 468

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Arun Kumar Saha
Sent: 24 April 2006 10:15
To: [hidden email]
Subject: [R] Problem with data frame

Dear r-users,

suppose I have n normal distributions with parameter N(0,i) i=1,2,.......,n
respectively.

Now I want to generate 500 random number for each distribution. And want to
put all 500*n random numbers
in a single data frame.

I tried with following code:

>n=20
random = data.frame(n)
for ( i in 2: length)
   {
    random[,i] = random(500,mean=0,sd=i)
   }

but while executing this I am getting errors.

Can anyone give me any suggestion?
Thanks and  regards
Arun

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Problem with data frame

Jacques Veslot-2
In reply to this post by Arun.stat
as.data.frame(replicate(20, rnorm(500)))

Arun Kumar Saha a écrit :

> Dear r-users,
>
> suppose I have n normal distributions with parameter N(0,i) i=1,2,.......,n
> respectively.
>
> Now I want to generate 500 random number for each distribution. And want to
> put all 500*n random numbers
> in a single data frame.
>
> I tried with following code:
>
>
>>n=20
>
> random = data.frame(n)
> for ( i in 2: length)
>    {
>     random[,i] = random(500,mean=0,sd=i)
>    }
>
> but while executing this I am getting errors.
>
> Can anyone give me any suggestion?
> Thanks and  regards
> Arun
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>


--
-------------------------------------------------------------------
[hidden email]
CNRS UMR 8090 - http://www-good.ibl.fr
Génomique et physiologie moléculaire des maladies métaboliques
I.B.L 2eme etage - 1 rue du Pr Calmette, B.P.245, 59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Problem with data frame

Gavin Simpson
In reply to this post by Arun.stat
On Mon, 2006-04-24 at 14:45 +0530, Arun Kumar Saha wrote:

>
> I tried with following code:
>
> >n=20
> random = data.frame(n)
> for ( i in 2: length)
>    {
>     random[,i] = random(500,mean=0,sd=i)
>    }
>
> but while executing this I am getting errors.

Did you check what you'd done above, or is what you posted not copied
and pasted directly from your R session (and therefore contains typos)?

      * data.frame(n) - doesn't make sense; you have data frame with one
        row/column containing the number 20
      * What is length?
      * If you want i=1,2,.......,n, why do you use "i in 2: length"?
      * What is random() [the function you are trying to use]?
      * What are the error messages - although one can have a good guess
        if you actually tried to run that code. You are asked by the
        posting guide to supply.

Does this help:

ran <- matrix(ncol = 20, nrow = 500)
for (i in 1:20)
{
  ran[, i] <- rnorm(500, sd = i)
}
ran <- as.data.frame(ran)

G

>
> Can anyone give me any suggestion?
> Thanks and  regards
> Arun
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
*  Note new Address, Telephone & Fax numbers from 6th April 2006  *
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                
ECRC & ENSIS                  [t] +44 (0)20 7679 0522
UCL Department of Geography   [f] +44 (0)20 7679 0565
Pearson Building              [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street                  [w] http://www.ucl.ac.uk/~ucfagls/cv/
London, UK.                   [w] http://www.ucl.ac.uk/~ucfagls/
WC1E 6BT.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html