I have a long data frame that I want to pivot wider.
f.tenuretot <- f.tenure_tmp %>% filter(grepl("TOT", tenure)) %>% select(NAME, tenure, value) %>%
pivot_wider(names_from=c(NAME, tenure), values_from= value)
I want the final data set to have the NAME values as column names, and for the first row to contain the values of the "tenure" variable.
Is there a way to do this?
TIA
Could you supply some sample data?
A handy way to supply data is to use the dput() function. Do dput(mydata) where "mydata" is the name of your dataset. For really large datasets probably dput(head(mydata, 100) will do. Paste it here between
```
```
adambickford:
f.tenuretot <- f.tenure_tmp %>% filter(grepl("TOT", tenure)) %>% select(NAME, tenure, value) %>%
pivot_wider(names_from=c(NAME, tenure), values_from= value)
does
pivot_wider(names_from=c(NAME), values_from= value)
not do that?
system
Closed
March 9, 2026, 1:28pm
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.