[R] creating a factor

Petr Pikal petr.pikal at precheza.cz
Tue Feb 3 14:52:54 CET 2004


Hallo

On 3 Feb 2004 at 20:43, Simon Hosking wrote:

> Hi list,
> I'd like to make a factor with seven 1s and three 2s using the
> factor() function. 
> That is,
> 

your.f <- factor(rep(c(1,2),c(7,3)))

> 1
> 1
> 1
> 1
> 1
> 1
> 1
> 2
> 2
> 2
> 
> 
> I will then bind this factor to the matrix below using
> cbind.data.frame().
> 
> 0.56	0.48
> 0.22	0.59
> 0.32	0.64
> 0.26	0.60
> 0.25	0.38
> 0.24	0.45
> 0.56	0.67
> 0.78	0.97
> 0.87	0.79
> 0.82	0.85
> 

your.frame<-cbind(your.f,your.matrix)

with your numbers ordered into 10x2 matrix like

cbind(factor(rep(c(1,2),c(7,3))),matrix(rnorm(20),10,2))
or
data.frame(var.f=factor(rep(c(1,2),c(7,3))),matrix(rnorm(20),10,2))


> 
> 
> I am new to R and have been using various manuals and have made many

Did you really follow examples from "An Introduction to R" manual?

> attempts without success any help appreciated. thanks, Simon

Cheers Petr


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

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list