[R] Converting chr to num

Jeff Reichman re|chm@nj @end|ng |rom @bcg|ob@|@net
Sun Aug 19 00:02:53 CEST 2018

Given it’s a variable would I just change the 12.6 in as.numeric(gsub(pattern = "%","","12.6%"))

To the variable name say … as.numeric(gsub(pattern = "%","",df$variable))



From: GALIB KHAN <ghk18 using scarletmail.rutgers.edu> 
Sent: Saturday, August 18, 2018 4:23 PM
To: reichmanj using sbcglobal.net
Cc: r-help using r-project.org
Subject: Re: [R] Converting chr to num


Hey there,


as.numeric(gsub(pattern = "%","","12.6%"))


On Sat, Aug 18, 2018 at 4:20 PM, Jeff Reichman <reichmanj using sbcglobal.net <mailto:reichmanj using sbcglobal.net> > wrote:

R-Help Forum

How do I convert a chr variable that contains percentages to an integer

Example 12.6% (chr) to 12.6 (int)


        [[alternative HTML version deleted]]

R-help using r-project.org <mailto:R-help using r-project.org>  mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]

More information about the R-help mailing list