

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 change the name of a data frame in R?
To change the name of a data frame, we can set the original name to the new name. Now both of the names can be used. Most of the times the purpose behind changing the name of the data frame is that, the original name does not seem to be a valid name based on the characteristics of the data. For example, if we have normally distributed columns in the data frame then we can name it as normal_distribution. This will help everyone to understand the data belongs to normal distribution.
Example1
set.seed(24) x<−rnorm(20,1,0.25) df1<−data.frame(x) df1
Output
x 1 0.8635298 2 1.1341463 3 1.1049058 4 0.8540932 5 1.2118650 6 1.0665055 7 1.1111463 8 0.8833762 9 0.7879075 10 1.0005780 11 0.6707730 12 1.1495673 13 0.8094464 14 0.6427274 15 1.0830611 16 0.8827348 17 0.9162533 18 1.3840630 19 1.1524986 20 1.1290839
Changing the name of df1 to Normal_Distribution −
Example
Normal_Distribution<−df1 Normal_Distribution
Output
x 1 0.8635298 2 1.1341463 3 1.1049058 4 0.8540932 5 1.2118650 6 1.0665055 7 1.1111463 8 0.8833762 9 0.7879075 10 1.0005780 11 0.6707730 12 1.1495673 13 0.8094464 14 0.6427274 15 1.0830611 16 0.8827348 17 0.9162533 18 1.3840630 19 1.1524986 20 1.1290839
Example2
y<−sample(0:5,20,replace=TRUE) df2<−data.frame(y) df2
Output
y 1 4 2 2 3 2 4 3 5 3 6 1 7 1 8 2 9 0 10 4 11 4 12 3 13 5 14 1 15 0 16 0 17 4 18 2 19 2 20 5
Changing the name of df2 to Random_Sample −
Example
Random_Sample<−df2 Random_Sample
Output
y 1 4 2 2 3 2 4 3 5 3 6 1 7 1 8 2 9 0 10 4 11 4 12 3 13 5 14 1 15 0 16 0 17 4 18 2 19 2 20 5
- Related Questions & Answers
- How to change the order of columns in an R data frame?
- How to change the name of data frames stored in an R list?
- How to add name to data frame columns in R?
- How to change the row order in an R data frame?
- How to change a text value in an R data frame?
- How to change the column names and row names of a data frame in R?
- How to change the order of one column data frame and get the output in data frame format in R?
- How to change the position of missing values to the end of data frame in R?
- How to change the name of variables in a list in R?
- How to name a data frame column with a vector value that has the same name in R?
- How to change the row index after sampling an R data frame?
- How to find the row median of columns having same name in R data frame?
- How to find the row variance of columns having same name in R data frame?
- How to find the row mean of columns having same name in R data frame?
- How to find the row total of columns having same name in R data frame?
Advertisements