mardi 28 septembre 2021

How I can sort these two columns using R

I have a large database, but here is a sample of it:

 df<-read.table (text=" Col1 Col2
        65  NA
        NA  91
        56  NA
        71  71
        67  100
        NA  45
        44  NA
        NA  90
        NA  40
        84  71
        44  63
        NA  20
    ", header=TRUE)

I want to add "1" to Col1 and complete NA in Col1 using Col2. Considering row 2, NA in Col1 would be 91. Here we do not add "1".In Col1, However, we add 1 at the beginning if they do not have NA.

The outcome of interest is:

   Out
    165
    91
    156
    171
    167
    45
    144
    90
    40
    184
    144
    20

Aucun commentaire:

Enregistrer un commentaire