[R] creating a new variable.

Ista Zahn istazahn at gmail.com
Tue Feb 19 02:32:14 CET 2013


Hi Nicole,

On Mon, Feb 18, 2013 at 7:01 PM, Nicole Ford <nicole.ford at me.com> 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.
>
> respondents will indicate which category they fall under.
>
> for the sake of ease, i will use small data as an example.
>
> i was thinking the levels would need to be created first-
>
> dem <- c(1,1,1,1,0,0,0,0)
>
> rep <- c(1,1,1,0,0,0,0,0)
>
> other <- c(1,0,0,0,0,0,0,0)
>
> then, i could do:
>
> party <-cbind(den, rep, other)

I don't really understand what you're trying to do. At this point you have

     dem rep other
[1,]   1   1     1
[2,]   1   1     0
[3,]   1   1     0
[4,]   1   0     0
[5,]   0   0     0
[6,]   0   0     0
[7,]   0   0     0
[8,]   0   0     0

so observation 1 is a dem, rep, and other, and observation 8 is none
of these. Doesn't really make sense to me.
>
> par1 <-factor(party)
>
> this is where i am getting stuck...  any thoughts would be appreciated.

Start with a clear idea of what the resulting data should look like.

Best,
Ista

>
> i promise this isn't homework.  i am trying to understand how i would go about creating variables if i choose to go in this direction in the future...  and work out the kinks now.
>
> ______________________________________________
> R-help at r-project.org 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