Hallo R Studio Community,
I am trying to prepare properly my data to be analyzed and I am stucked in this issue.
I have dataframe similar to this reprex
df = data.frame(pt_name=c("mario","mario","mario","luigi","luigi","luigi","toad","toad","toad"),
pod=rep(c(1,2,3),3),
crea=c(0.4,0.5,0.4,1,2,2.5,4,4.5,6),
other_value=rep(c(NA),9))
When I call df I obtain
pt_name pod crea other_value
1 mario 1 0.4 NA
2 mario 2 0.5 NA
3 mario 3 0.4 NA
4 luigi 1 1.0 NA
5 luigi 2 2.0 NA
6 luigi 3 2.5 NA
7 toad 1 4.0 NA
8 toad 2 4.5 NA
9 toad 3 6.0 NA
I would like to convert in this way
df_wish = data.frame(pt_name =c("mario","luigi","toad"),
crea_pod_1 = c(0.4, 1, 4),
crea_pod_2 = c(0.5, 2, 4.5),
crea_pod_3 = c(0.4, 2.5, 6),
other_value_pod_1 = rep(c(NA),3),
other_value_pod_2 = rep(c(NA),3),
other_value_pod_3 = rep(c(NA),3))
So that I can obtain
pt_name crea_pod_1 crea_pod_2 crea_pod_3 other_value_pod_1 other_value_pod_2 other_value_pod_3
1 mario 0.4 0.5 0.4 NA NA NA
2 luigi 1.0 2.0 2.5 NA NA NA
3 toad 4.0 4.5 6.0 NA NA NA
is there any simple function to do this? ( I am beginner in R)
Thanks in advance!