mardi 3 février 2015

Filling 3rd column based on value of 2nd column in data frame in R

I want to check if the 2nd column of my data frame has an empty value or not and fill a third column called "label" accordingly.


Data Frame is like this:



col1 col2 label
hello there both filled
this that both filled
start "" col2 empty


I am trying this:



for (i in nrow(dataframe)) {

if (isTRUE(dataframe[i,c('col2')] == "") == TRUE)
{ dataframe[i,]$label <- "both filled" }
else{
dataframe[i,]$label <- "col2 empty" }
}
}


But all I get is the same label for every row


Aucun commentaire:

Enregistrer un commentaire