Skip to content
Back to formatted view

Raw Message

Message-ID: <5.1.0.14.2.20040203080536.0205bbc0@127.0.0.1>
Date: 2004-02-03T13:08:50Z
From: John Fox
Subject: creating a factor
In-Reply-To: <1075801398.4771.15.camel@localhost.localdomain>

Dear Simon,

One doesn't generally use cbind.data.frame() directly, but rather through 
the generic function cbind(). I believe that the following will give you 
what you want:

fac <- factor(c(rep(1,7), rep(2,3)))
cbind(fac, as.data.frame(mat))

where mat is the matrix.

I hope that this helps,
  John



At 08:43 PM 2/3/2004 +1100, Simon Hosking wrote:
>Hi list,
>I'd like to make a factor with seven 1s and three 2s using the
>factor() function.
>That is,
>
>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
>
>
>
>I am new to R and have been using various manuals and have made many 
>attempts without success
>any help appreciated.
>thanks,
>Simon

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox