Skip to content
Back to formatted view

Raw Message

Message-ID: <5122E0A5.6050302@bitwrit.com.au>
Date: 2013-02-19T02:17:09Z
From: Jim Lemon
Subject: creating a new variable.
In-Reply-To: <1B5EB635-6013-4892-97E7-7F6225B1F7F6@me.com>

On 02/19/2013 11:01 AM, Nicole Ford wrote:
> hello, all.
>
> in my previous research, i have always used existing data.  i am trying something new as an exploratory exercise and have never create my own variable form scratch.
>
> essentially, i am creating a variable for party affiliation.
>
> here is an example.
>
> var =party.
>
> levels= democrat, republican, other.
> ...
> this is where i am getting stuck...  any thoughts would be appreciated.
>
Hi Nicole,
The usual way something like this is done is to create a factor of a 
given size with the appropriate levels:

party<-factor(sample(c("dem","rep","oth"),100,TRUE))
  party
   [1] dem dem dem rep oth dem dem oth rep dem rep rep oth dem oth oth 
dem dem
  [19] oth rep oth rep dem oth rep dem oth oth oth oth rep dem oth dem 
oth rep
  [37] dem oth dem oth rep oth rep oth rep dem dem rep rep rep dem oth 
dem dem
  [55] oth dem rep dem rep oth rep oth dem dem dem rep dem rep dem oth 
rep rep
  [73] rep dem rep rep rep dem oth oth oth rep oth rep oth oth dem oth 
rep dem
  [91] rep rep oth dem rep dem dem oth dem dem
Levels: dem oth rep

Jim