Hello, Try the following.
levels <- c("democrat", "republican", "other") 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) party <- factor(rep(levels, c(sum(dem), sum(rep), sum(other)))) party Hope this helps, Rui Barradas Em 19-02-2013 00:01, Nicole Ford escreveu:
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) par1 <-factor(party) this is where i am getting stuck... any thoughts would be appreciated. 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@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.
______________________________________________ R-help@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.