You can create a new column in a dataframe that contains the minimum number from a specific column while ignoring NA values in R using the mutate
function from the dplyr
package. Here's an example to achieve this:
340 chars13 lines
In this code snippet, we first load the dplyr
package. Then, we create an example dataframe df
. We use the mutate
function twice to first remove NA values from column 'x' using na.omit
and then calculate the minimum value of the remaining elements using min
. The na.rm = TRUE
argument in min
ensures that NA values are ignored during calculation.
After running this code, you will have a new column min_x
in the dataframe df
that contains the minimum value of the 'x' column while ignoring NA values.
gistlibby LogSnag