[R] FW: recoding problem

Joshua Wiley jwiley.psych at gmail.com
Fri Jul 23 17:10:26 CEST 2010


Hi Tom,

This seems to work like I'd expect:

HGlt10RawPerc2008 <- read.table(textConnection("
-5
 0
-1
-1
 0
 2
 3
-5
-2
 0
 2
 0
 1
-2
 3
 0
 4
 1
 4
 2
"))

recode(HGlt10RawPerc2008 ,"-100:0.0 = 10; 0:1.0 = 8; 1.001:3.0 = 6;
3.001:4.0 = 4; 4.001:5.0 = 2; else = 0")

I wonder if your data might not be something like 10.0000001 which
would print as 10, but behave in calculations slightly differently?

Also, the output of this might be informative.

str(HGlt10RawPerc2008)

Cheers,

Josh

On Fri, Jul 23, 2010 at 7:47 AM, Heiman, Thomas J. <theiman at mitre.org> wrote:
>
>
> Hi,
>
>
>
> I am trying to recode the output from a matrix(here is a small snippet of it):
>
>
>
> HGlt10RawPerc2008[1:20]
>
>  [1] -5
>
>      0
>
>     -1
>
>     -1
>
>      0
>
>      2
>
>      3
>
>     -5
>
>     -2
>
>      0
>
>      2
>
>      0
>
>      1
>
>     -2
>
>      3
>
>      0
>
>      4
>
>      1
>
>      4
>
>      2
>
>
>
> Here is the code I am using to recode it:
>
>
>
> HGBlt10Points2008 = recode(HGlt10RawPerc ,"-100:0.0=10; 0:1.0=8; 1.001:3.0=6; 3.001:4.0=4; 4.001:5.0=2;else=0 ")
>
>
>
> The output that I am expecting and what I get are:
>
>
> What it should be
>
>     The output of
>          my code
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 8*
>
> 6
>
> 6
>
> 6
>
> 4*
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 10
>
> 6
>
> 10*
>
> 10
>
> 10
>
> 8
>
> 10*
>
> 10
>
> 10
>
> 6
>
> 6
>
> 10
>
> 8*
>
> 2
>
> 0*
>
> 8
>
> 0*
>
> 2
>
> 6*
>
> 6
>
> 10*
>
>
>
>
> The differences between my output and what I wanted are marked with a "*".. Any ideas on what I am doing wrong?  Thank you!!
>
>
>
> Sincerely,
>
>
>
> tom
>
>        [[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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list