![]() |
In this article, we will discuss the difference between setNames and setnames methods with examples in R Programming language. setNames:setNames is available in stats package, used to name the elements in a vector.
Example: In this example, we are going to create a vector with 10 elements and assign the letters as names with setNames() method. R
Output: a b c d e f g h i j 1 2 3 4 5 6 7 8 9 10 setnames:setnames are available in data.table package used to name the columns in a data frame.
Example: In this example, we are going to create a dataframe with 3 elements and rename the column names using setnames() method. We specified columns as v1,v2 and v3, now we will rename them to col1, col2, and col3. R
Output: The differences that we observed is v1 v2 v3 1 1 6 11 2 2 7 12 3 3 8 13 4 4 9 14 5 5 10 15 col1 col2 col3 1 1 6 11 2 2 7 12 3 3 8 13 4 4 9 14 5 5 10 15 setnames() is available in data.table() package and setNames() is available in stats package. |
Reffered: https://www.geeksforgeeks.org
Difference Between |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |