- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to standardize columns in an R data frame?
This can be done by using scale function.
Example
> data<- data.frame(x = rnorm(10, 50, 1.5), y = runif(10, 2, 5)) > data x y 1 49.57542 2.940931 2 49.51565 2.264866 3 50.70819 2.918803 4 49.09796 2.416676 5 49.90089 2.349696 6 49.03445 3.883145 7 51.29564 4.072614 8 49.11014 3.526852 9 49.41255 3.320530 10 49.42131 3.033730 > standardized_data <- scale(data) > standardized_data x y [1,] -0.1774447 -0.20927607 [2,] -0.2579076 -1.28232321 [3,] 1.3476023 -0.24439768 [4,] -0.8202493 -1.04137095 [5,] 0.2607412 -1.14768085 [6,] -0.9057468 1.28619932 [7,] 2.1384776 1.58692277 [8,] -0.8038439 0.72069363 [9,] -0.3967165 0.39321942 [10,] -0.3849124 -0.06198639 attr(,"scaled:center") x y 49.707220 3.072784 attr(,"scaled:scale") x y 0.7427788 0.6300430
- Related Articles
- How to standardize selected columns in R data frame?
- How to standardize columns if some columns are categorical in R data frame?
- How to standardize only numerical columns in an R data frame if categorical columns also exist?
- How to subset factor columns in an R data frame?
- How to reorder the columns in an R data frame?
- How to concatenate numerical columns in an R data frame?
- How to convert columns of an R data frame into rows?
- How to select only numeric columns from an R data frame?
- How to create histogram of all columns in an R data frame?
- How to change the order of columns in an R data frame?
- How to standardize selected columns in data.table object in R?
- How to add a prefix to columns of an R data frame?
- How to compare two columns in an R data frame for an exact match?
- How to add name to data frame columns in R?
- How to find the median of all columns in an R data frame?

Advertisements