0

I have a dataframe:

Store <- c('A','A','A', 'B','C','C')
Main_or_branch <- c('main', 'Branch','Branch','main','main', 'Branch')
flavor <- c('chocolate', 'N/A','N/A', 'vanilla', 'strawberry','N/A')

df <- data.frame(Store, Main_or_branch, flavor)

and it looks like this:

 Store Main_or_branch flavor    
 <fct> <fct>          <fct>     
1 A     main           chocolate 
2 A     Branch         N/A       
3 A     Branch         N/A       
4 B     main           vanilla   
5 C     main           strawberry
6 C     Branch         N/A   

I'm trying to use group by and fill :

df %>% group_by(Store) %>% fill(flavor)

but my output still looks like this

  Store Main_or_branch flavor    
  <fct> <fct>          <fct>     
1 A     main           chocolate 
2 A     Branch         N/A       
3 A     Branch         N/A       
4 B     main           vanilla   
5 C     main           strawberry
6 C     Branch         N/A   

Does anyone know what the issue could be? Thanks!

Stacy
  • 87
  • 4
  • Can you show your expected output? Do you need `df %>% group_by(Store) %>% fill(Top_flavor)` This uses `dplyr` and `tidyr` library. – Ronak Shah Sep 30 '21 at 03:33
  • Note that string values if `'N/A'` are not the same as the special R value `NA` so it won't be recognized as "missing". Normally when you import your data you can specify what value is used for missing if it's non-standard such as this one. – MrFlick Sep 30 '21 at 05:22

0 Answers0