I want to rearrange the following data frame:
set.seed(45)
data <- data.frame(
name = rep(c("FirstName", "SecondName"), each=4),
numbers = rep(1:4, 2),
value = rnorm(8)
)
data
name numbers value
1 FirstName 1 0.3407997
2 FirstName 2 -0.7033403
3 FirstName 3 -0.3795377
4 FirstName 4 -0.7460474
5 SecondName 1 -0.8981073
6 SecondName 2 -0.3347941
7 SecondName 3 -0.5013782
8 SecondName 4 -0.1745357
I want to re arrange in such a way that each unique"name" variable is a row name, with the values as "observations" along that row. Also, I want the "numbers" as columns. You can refer below for example:
name 1 2 3 4
1 FirstName 0.3407997 -0.7033403 -0.3795377 -0.7460474
5 SecondName -0.8981073 -0.3347941 -0.5013782 -0.1745357
Can somebody please help?