How to convert character of percentage into numeric in R

I run into a problem when converting character of percentage to numeric. E.g. I want to convert "10%" into 10%, but


returns NA. Do you have any ideas?


10% is per definition not a numeric vector. Therefore, the answer NA is correct. You can convert a character vector containing these numbers to numeric in this fashion:

percent_vec = paste(1:100, "%", sep = "")
as.numeric(sub("%", "", percent_vec))

This works by using sub to replace the % character by nothing.

Need Your Help

nvarchar(max) vs NText

sql-server sql-server-2005 sql-server-2008 text nvarchar

What are the advantages and disadvantages of using the nvarchar(max) vs. NText data types in SQL Server? I don't need backward compatibility, so it is fine that nvarchar(max) isn't supported in old...

SharePoint 2010 external list will not export to Outlook

sharepoint sharepoint-2010 outlook exchange-server

I have created an external content type in SharePoint 2010 that populates a list from SQL. The list is successfully populated and I can view it through SharePoint. However, if I select the option to

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.