HoHoHo
HoHoHo

Reputation: 311

If statement combined with random row names

It seems to be a trivial question but i could not find out how to solve it. Based on rownames of DF i need to fill the column. If rowname=1, column a=i, otherwise do not fill with anything.

DF
   a
2  
4
1
4

I have tried if statement and DF[rownames(DF)==1]<-i, that did nothing. Thank you for any suggestion.

Upvotes: 2

Views: 557

Answers (1)

akrun
akrun

Reputation: 887153

We can use ifelse

DF$Col2 <- ifelse(row.names(DF)==1, "i", "")

Upvotes: 2

Related Questions