[R] How do I generate a grid of data in [0,1]?

Greg Snow Greg.Snow at intermountainmail.org
Tue Aug 7 22:10:13 CEST 2007


Try:

data <- expand.grid( a= seq(0,1,.1), b= seq(0,1,.1) )

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of esh
> Sent: Tuesday, August 07, 2007 1:59 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] How do I generate a grid of data in [0,1]?
> 
> Hello, my objective is to produce a data.frame that 
> represents a grid of data points evenly spaced as closely 
> together as possible on a graph with domain and range both 
> being [0,1].  I tried to get a smaller example working first 
> and I tried the following code:
> > sink(file="Rsampledata")
> > a<-0
> > while(a<1) {data<-data.frame(a,seq(0,1,0.1)); print(data); a<-a+0.1}
> 
> My output was: 
>    a seq.0..1..0.1.
> 1  0            0.0
> 2  0            0.1
> 3  0            0.2
> 4  0            0.3
> 5  0            0.4
> 6  0            0.5
> 7  0            0.6
> 8  0            0.7
> 9  0            0.8
> 10 0            0.9
> 11 0            1.0
>      a seq.0..1..0.1.
> 1  0.1            0.0
> 2  0.1            0.1
> 3  0.1            0.2
> 4  0.1            0.3
> 5  0.1            0.4
> 6  0.1            0.5
> 7  0.1            0.6
> 8  0.1            0.7
> 9  0.1            0.8
> 10 0.1            0.9
> 11 0.1            1.0
>      a seq.0..1..0.1.
> 1  0.2            0.0
> 2  0.2            0.1
> 3  0.2            0.2
> 4  0.2            0.3
> 5  0.2            0.4
> 6  0.2            0.5
> 7  0.2            0.6
> 8  0.2            0.7
> 9  0.2            0.8
> 10 0.2            0.9
> 11 0.2            1.0
>      a seq.0..1..0.1.
> 1  0.3            0.0
> 2  0.3            0.1
> 3  0.3            0.2
> 4  0.3            0.3
> 5  0.3            0.4
> 6  0.3            0.5
> 7  0.3            0.6
> 8  0.3            0.7
> 9  0.3            0.8
> 10 0.3            0.9
> 11 0.3            1.0
>      a seq.0..1..0.1.
> 1  0.4            0.0
> 2  0.4            0.1
> 3  0.4            0.2
> 4  0.4            0.3
> 5  0.4            0.4
> 6  0.4            0.5
> 7  0.4            0.6
> 8  0.4            0.7
> 9  0.4            0.8
> 10 0.4            0.9
> 11 0.4            1.0
>      a seq.0..1..0.1.
> 1  0.5            0.0
> 2  0.5            0.1
> 3  0.5            0.2
> 4  0.5            0.3
> 5  0.5            0.4
> 6  0.5            0.5
> 7  0.5            0.6
> 8  0.5            0.7
> 9  0.5            0.8
> 10 0.5            0.9
> 11 0.5            1.0
>      a seq.0..1..0.1.
> 1  0.6            0.0
> 2  0.6            0.1
> 3  0.6            0.2
> 4  0.6            0.3
> 5  0.6            0.4
> 6  0.6            0.5
> 7  0.6            0.6
> 8  0.6            0.7
> 9  0.6            0.8
> 10 0.6            0.9
> 11 0.6            1.0
>      a seq.0..1..0.1.
> 1  0.7            0.0
> 2  0.7            0.1
> 3  0.7            0.2
> 4  0.7            0.3
> 5  0.7            0.4
> 6  0.7            0.5
> 7  0.7            0.6
> 8  0.7            0.7
> 9  0.7            0.8
> 10 0.7            0.9
> 11 0.7            1.0
>      a seq.0..1..0.1.
> 1  0.8            0.0
> 2  0.8            0.1
> 3  0.8            0.2
> 4  0.8            0.3
> 5  0.8            0.4
> 6  0.8            0.5
> 7  0.8            0.6
> 8  0.8            0.7
> 9  0.8            0.8
> 10 0.8            0.9
> 11 0.8            1.0
>      a seq.0..1..0.1.
> 1  0.9            0.0
> 2  0.9            0.1
> 3  0.9            0.2
> 4  0.9            0.3
> 5  0.9            0.4
> 6  0.9            0.5
> 7  0.9            0.6
> 8  0.9            0.7
> 9  0.9            0.8
> 10 0.9            0.9
> 11 0.9            1.0
>    a seq.0..1..0.1.
> 1  1            0.0
> 2  1            0.1
> 3  1            0.2
> 4  1            0.3
> 5  1            0.4
> 6  1            0.5
> 7  1            0.6
> 8  1            0.7
> 9  1            0.8
> 10 1            0.9
> 11 1            1.0
> 
> This does produce the kind of data points that I will need, 
> however I need all these data points in one single data.frame 
> instead of 11 because of further formatting I must do with 
> the data.  Any suggestions?
> Thank you,
> Elysia
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list