![]() |
In this article, we will explore various methods to convert the pivot data from long to wide format by using R Programming Language. How to convert the pivot data from long to wide formatR language offers various methods to convert the pivot data from long to wide format. By using these methods, can work more efficiently. Some of the methods to convert pivot data from long to wide format are: By using the reshape() functionThis method is used to convert the pivot data from long to wide format efficiently. In the below example, we created a data frame and converted the pivot data from long to wide format.
Output: [1] "Long format of pivot data"
ID Time Values
1 1 1 10
2 1 2 11
3 1 3 12
4 2 1 13
5 2 2 14
6 2 3 15
[1] "Wide format of pivot data"
ID Values.1 Values.2 Values.3
1 1 10 11 12
2 2 13 14 15
In the below example, we created a data frame and converted the pivot data from long to wide format.
Output: [1] "The long-format of pivot data"
Student Subject Score
1 A Physics 80
2 B Science 75
3 C Physics 85
4 A Science 90
5 B Physics 85
6 C Science 88
[1] "Wide-format of pivot data"
Student Score.Physics Score.Science
1 A 80 90
2 B 85 75
3 C 85 88 By using the base R functionsThis method is used to convert the pivot data from long to wide format efficiently. In the below example, we created a data frame and converted the pivot data from long to wide format.
Output: [1] "Long-format of pivot data"
rno Time Values
1 1 1 10
2 1 2 20
3 1 3 30
4 1 4 40
5 2 1 50
6 2 2 60
7 2 3 70
8 2 4 80
[1] "Wide formmat of pivot data"
rno Time1 Time2 Time3 Time4
1 1 10 20 30 40
2 2 50 60 70 80 In the below example, we created a data frame and converted the pivot data from long to wide format.
Output: [1] "Long format of pivot data"
ID name Value
1 2 C 10
2 2 D 20
3 6 C 30
4 6 D 40
[1] "wide format of pivot data"
ID C D
1 2 10 20
2 6 30 40 ConclusionIn Conclusion, we learned about how to convert the pivot data from long to wide format by using R. R language offers versatile tools while converting the pivot data from long to wide format. |
Reffered: https://www.geeksforgeeks.org
R Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |