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

I have a data frame where one particular column has a set of
specific values (let's say, 1, 2, ..., 23). What I would like to do is
to convert from this layout to the one, where the frame would have
extra 23 (in this case) columns, each one representing one of the
factor values. The data in these columns would be booleans indicating
whether a particular row had a given factor value... To show a
specific example:


Source frame:


ID
DATE SECTOR
123 2008-01-01 1
456
2008-01-01 3
789 2008-01-02 5
... <more records
with SECTOR values from 1 to 5>

Desired forma

Development Tools & Services

I have a data frame. Let's call him bob:

/>> head(bob)
phenotype
exclusion
GSM399350 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1-
Gr1- TER119-
GSM399351 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1-
TER119-
GSM399352 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1-
TER119-
GSM399353 3- 4- 8- 25+ 44+ 11b- 11c- 19- NK1.1- Gr1-
TER119-
GSM399354 3- 4- 8- 25+ 44+ 11b- 11c- 19- NK1.1- Gr1-
TER119-
GSM399355 3- 4- 8- 25+ 44+ 11b- 11c- 19- NK1.1- Gr1-
TER119-

I'd like to concatenate the rows of this
data frame (this will be another question). But look:


<
Programming Languages

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

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?
Programming Languages

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

Web Development

This question already has an answer here:




  • href="/questions/3418128/how-to-convert-a-factor-to-an-integer-numeric-without-a-loss-of-information"
    dir="ltr">How to convert a factor to an integer
    umeric without a loss of information

    3 answers





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?

Web Development

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow