Data in R can be converted from one class to the other. The function is prefixed with **as.** then followed by the name of the data class that we wish to convert to. Data class in R are the following:

- numeric –
**as.numeric**
- vector –
**as.vector**
- character –
**as.character**
- matrix –
**as.matrix**
- data frame –
**as.data.frame**

Hence, if one wishes to convert a numeric data points 32, 35, 38, 29, 27, 40, and 33 into a character. Then, this is achieved by

Notice the difference between the output of the **data** variable and the converted one, **data.ch**. The output differs only with this character ‘ ” ‘. This character that encloses every data points suggests that the data is now in character form. And this can be verified using the function **class**,

Consider this data,

These objects are in numeric class, and converting these to data frame with three variables, would be

And this can be further converted to matrix class,

*Related*

To

**leave a comment** for the author, please follow the link and comment on their blog:

** Analysis with R**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as:

Data science,

Big Data, R jobs, visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...