'In r studio when using mutate() in combination with c_across() all rows are returning the same value

I am fairly new to r and am working with a large, spectral data set. I am wanting to average red and NIR wavelegnths' reflectance for each sample. Using pivot_wider I have wavelengths 350-2500 displayed as columns containing reflectance. I tried (using dplyr):

df%>%
  pivot_wider(names_from=Wavelength,values_from=Reflectance,names_prefix="W")%>%
  mutate(red=(mean(c_across(W600:W700))))%>%
  mutate(nir=(mean(c_across(W720:W1300))))

When I did this, the same value was returned for each sample in the new columns, which is incorrect. There was no error message. Any help is appreciated, thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source