dimanche 20 septembre 2020

Randomly select a value from a row that is not NA from a data frame in R

I have a data frame that has a series of values, some of which are NA - I'd like to at random sample one of the values that are not NA

An example below:

df1

col1    col2   col3
  1       4      NA
  2       NA      1
  NA       4      7

I would like a vector that then is a result of selecting one of the values from each row that is not NA.




Aucun commentaire:

Enregistrer un commentaire