[R] creating new variable
PIKAL Petr
petr.pikal at precheza.cz
Mon Sep 24 14:51:02 CEST 2012
Hi
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Niklas Fischer
> Sent: Thursday, September 20, 2012 11:13 PM
> To: r-help at r-project.org
> Subject: [R] creating new variable
>
> Dear R-helper
>
> I have a data which is about stregth of personal relationship There are
> two important variable , first one shows if there is a relationship,
> second one how strong it is.
>
> I'd like to create dummy variable which is a combination of these two
> variables and shows strength of personal relationships.
> The problem is while first input variable is dummy, the second one is
> five level likert data (1: very weak, 5 very strong) I would create new
> variable including three categories (weak, moderate, and
> strong) but I have to create two categories.
Well I am a little lost in your explanation maybe you could show us part of your variables.
Anyway if rel is existence of relation
> rel<-sample(0:1, 10, replace=T)
and int is intensity of relation
> int<-sample(1:5, 10, replace=T)
whole <-int*rel
[1] 2 1 5 2 5 0 4 4 0 2
Gives you 0 where there is no relation and numbers 1:5 showing intensity of relation
change it to factor
whole <-factor(whole)
and chase levels
levels(whole) <-rep(c("weak", "medium", "strong"), each=2)
Regards
Petr
> Do you know any way to do so.
>
> Regards,
> Niklas
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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