pivotwider(namesfrom = coefficientsname, valuesfrom = coefficients, valuesfill =…
- User
pivot_wider(names_from = coefficients_name, values_from = coefficients, values_fill = TIME_LIMIT) I want to fill different values for different columns. is there an easy way to do this?
Assistant
The short answer is no, you cannot do this directly inside pivot_wider when you have a single values_from column.The values_fill argument is designed to map to the source column (in your case, coefficients), not the destination column names (the levels of coefficients_name).Here are the two best ways to handle this using standard dplyr and tidyr workflows.Method 1: replace_na() (Best for a small number of columns)If you only have a few columns to fill, the easiest way is to pivot first, then manually fill the NAs in the specific columns using mutate and tidyr338d:4ae:8115:65fb:def0:70e2:57f6:2f00replace_na().Rlibrary(tidyverse)