[R] Help in expand.grid() (Restricted combination)

Berton Gunter gunter.berton at gene.com
Thu Nov 3 23:39:44 CET 2005


If I understand you correctly, you cannot do this with a data.frame, which
must be rectangular with equal numbers of entries (columns) in each row. See
?.data.frame and read "An Introduction to R" for these basics.  You could
make the 3rd column for exhaustive = NA (or maybe an empty string, "") I
suppose, and rbind the results you want:

part1<-expand.grid(e='nearest-neighbor',d=c(70,75,80,85,90,92,94,96,98,99),
	n=c(20,25,30,35,40))

part2<-data.frame(e='exhaustive',d=c(70,75,80,85,90,92,94,96,98,99),n=NA)

result<-rbind(part1,part2)


-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Prasanna
> Sent: Thursday, November 03, 2005 12:07 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Help in expand.grid() (Restricted combination)
> 
> Dear Rs:
> 
> BY having the following code:
> 
> candidates<-expand.grid(e=c("nearest-neighbor","exaustive"),
> d=c(70,75,80,85,90,92,94,96,98,99),
> n=c(20,25,30,35,40))
> 
> results in :
> 
> e d n
> 1 nearest-neighbor 70 20
> 2 exaustive 70 20
> 3 nearest-neighbor 75 20
> 4 exaustive 75 20
> ................
> 90 exaustive 90 40
> 91 nearest-neighbor 92 40
> 92 exaustive 92 40
> 93 nearest-neighbor 94 40
> 94 exaustive 94 40
> 95 nearest-neighbor 96 40
> 96 exaustive 96 40
> 97 nearest-neighbor 98 40
> 98 exaustive 98 40
> 99 nearest-neighbor 99 40
> 100 exaustive 99 40
> 
> 
> I need to associate "nearest-neighbor" with
> d=c(70,75,80,85,90,92,94,96,98,99), n=c(20,25,30,35,40)
> but "exaustive" only with d=c(70,75,80,85,90,92,94,96,98,99). 
> Therefore I
> will have only 50+10 combinations not 100.
> I need to have combination as shown below
> 
> 1 nearest-neighbor 70 20
> 2 exaustive 70
> 3 nearest-neighbor 75 20
> 4 exaustive 75
> ................
> 60
> 
> Thanks
> Prasanna
> 
> 
> --
> Prasanna BALAPRAKASH
> IRIDIA, Universiti Libre de Bruxelles
> 50, Av. F. Roosevelt, CP 194/6
> 1050 Brussels
> Belgium.
> 
> 	[[alternative HTML version deleted]]
> 
>




More information about the R-help mailing list