Using if else on a dataframe across multiple columns

后端 未结 6 1444
情书的邮戳
情书的邮戳 2021-01-14 21:43

I have a large dataset of samples with descriptors of whether the sample is viable - it looks (kind of) like this, where \'desc\' is the description column and \'blank\' ind

6条回答
  •  时光取名叫无心
    2021-01-14 22:19

    Using your first initial approach with loops I figured out this:

        for(i in 1:nrow(dat)){
      if(dat[i, 1] =="blank"){
        dat[i, 2:4] <- NA
      } 
      else {
        dat[i,length(dat)] <- dat[i, length(dat)]
      }
    }
    

    I tested it with your data and worked. Hope this is useful for everyone dealing with loops in rows and columns with conditions.

提交回复
热议问题