[R] recoding variables-recode not working
David Winsemius
dwinsemius at comcast.net
Wed Apr 7 20:10:12 CEST 2010
On Apr 7, 2010, at 1:50 PM, Vlatka Matkovic Puljic wrote:
> atomic [1:1578] 0 0 0 0 0 0 0 0 0 0 ...
> - attr(*, "levels")= chr "0=0,1:33=1"
Can you go back to where you got this data and start over? You have
made something that looks quite strange. It appears to be neither a
vector of mode atomic (since they are not supposed to have attributes)
nor does str think it is a factor, although the levels attribute is
suggesting that some operation tried to make it one. You might get
further insight by trying:
summary(Q12) # it would tell you if it is dichotomous and the
proportions are sensible.
... and its possible that you could still succeed in coercing to
factor and then changing hte level labels (not lables) to what you
desire. Perhaps:
Q12f <- factor(Q12)
levels(Q12f) <- c('0', '1 and more')
>
> 2010/4/7 David Winsemius <dwinsemius at comcast.net>
>
> On Apr 7, 2010, at 1:31 PM, Vlatka Matkovic Puljic wrote:
>
> Hi,
>
> I have numerical variable that I want to recode into categories '0'
> and '1
> and more' and do analysis with that data.
> I have tried various of possibilities to do so, but I am sucked and
> nothing
> is working.
>
> recode(Q12, "0='A';1:30='B'")
> cut(Q12, breaks=c(0,1,30), lables=c('0', '1 and more'))
> cat(Q12, "0=0;1-33=1")
>
> What should I do to make it right?
>
> What does str(Q12) return?
>
>
> --
> **************************
> Vlatka
>
> [[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.
>
> David Winsemius, MD
> West Hartford, CT
>
>
>
>
> --
> **************************
> Vlatka Matković Puljić
> 095/8618 171
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list