I searched similar questions but couldn't find an answer to what I am trying to achieve. I have a dataset that is set up like so:
ID    Trial   Treatment   Frequency  Value   
A       1      Control    8000       65.1   
A       1      Top        8000       62.8    
A       1      Bottom     8000       60.3  
A       1      Control    9000       63.1   
A       1      Top        9000       66.2    
A       1      Bottom     9000       69.8
A       2      Control    8000       67.6   
A       2      Top        8000       63.4    
A       2      Bottom     8000       71.9 
A       2      Control    9000       59.7  
A       2      Top        9000       63.3  
A       2      Bottom     9000       57.2 
Each ID (altogether there are 27) is subjected to three Treatment of playbacks of sounds at either 8000 or 9000 Hz (Frequency). The process is repeated twice, meaning there are multiple Trial.
I want to use pivot_wider on the Treatment column to end up with a table that looks like:
ID   Trial   Frequency   Control   Top   Bottom   
A    1       8000        65.1      62.8  60.3
A    2       8000        67.6      63.4  71.9  
A    1       9000        63.1      66.2  69.8
A    2       9000        59.7      63.3  57.2
Reproducible data:
df <- read.table(text="ID  Trial  Treatment   Frequency  Value   
A       1      Control    8000  65.1   
A       1      Top    8000  62.8    
A       1      Bottom   8000  60.3  
A       1      Control    9000  63.1   
A       1      Top    9000  66.2    
A       1      Bottom  9000  69.8 
A       2      Control  8000  67.6  
A       2      Top      8000  63.4  
A       2      Bottom   8000   71.9 
A       2      Control    9000  59.7  
A       2      Top      9000  63.3  
A       2      Bottom     9000  57.2", strin=F,h=T)