[R] How do I Convert "<1" to the number 1?

John Fox jfox at mcmaster.ca
Wed Sep 24 18:02:58 CEST 2008


Dear Tom,

I don't know whether it qualifies as elegant or clever, but you should
be able to use sub(), as in

> as.numeric(sub("<", "", c("1", "< -2", "<1")))
[1]  1 -2  1

I hope this helps,
 John

On Wed, 24 Sep 2008 08:08:21 -0700 (PDT)
 Tom La Bone <booboo at gforcecable.com> wrote:
> 
> Is there an elegant way in R to change a number reported as a
> less-than
> number in text format, "<1" for example, to the numeric equivalent 1?
> I have
> been trying to use as.numeric, but have not come up with anything
> clever
> yet.
> 
> Tom
>  
> -- 
> View this message in context:
>
http://www.nabble.com/How-do-I-Convert-%22%3C1%22-to-the-number-1--tp19651018p19651018.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.

--------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/



More information about the R-help mailing list