convert hyphen to zero in data frame then convert affected columns to numeric in R



I have data sets in which a hyphen is used in place of the number zero, as in the example data set my.data below. I can replace the hyphens with zeroes, but then have trouble converting the affected columns to numeric. My actual data sets are very large with many columns and I do not know which columns will contain hyphens. The data sets are also too large and complex for me to feel comfortable using Find and Replace within the data sets themselves before reading them into R.


I think the first three columns of the actual data sets will be character and the rest of the columns should be numeric (if it were not for the hyphens). Is there an efficient and


Related to : convert hyphen to zero in data frame then convert affected columns to numeric in R
convert hyphen to zero in data frame then convert affected columns to numeric in R
Development Tools & Services

I have data sets in which a hyphen is used in place of the number zero, as in the example data set my.data below. I can replace the hyphens with zeroes, but then have trouble converting the affected columns to numeric. My actual data sets are very large with many columns and I do not know which columns will contain hyphens. The data sets are also too large and complex for me to feel comfortable using Find and Replace within the data sets themselves before reading them into R.


I think the first three columns of the actual data sets will be character and the rest of the columns should be numeric (if it were not for the hyphens). Is there an efficient and

How to convert a data frame column to numeric type?
22/11/2014 10:00 am Development Tools & Services

How do you convert a data frame column to a numeric type?


How to convert data.frame column from Factor to numeric [duplicate]
17/12/2014 5:50 pm Development Tools & Services

This question already has an answer here:

I have a data.frame whose class column is Factor. I'd like to convert it to numeric so that I can use correlation matrix.

> str(breast)
'data.frame':   699 obs. of  10 variables:
 ....
 $ class                   : Factor w/ 2 levels "2","4": 1 1 1 1 1 2 1
1 1 1 ...
> table(breast$class)
  2   4 
458 241
> cor(breast)
Error in cor(breast) : 'x' must be numeric

How can I convert a Factor column to a numeric column?


Convert all data frame character columns to factors
Development Tools & Services

Given a (pre-existing) data frame that has columns of various types, what is the simplest way to convert all its character columns to factors, without affecting any columns of other types?


HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .