#Do apply(y,1,print)
#Note the space that is inserted before the "1." If you insert this space in your function apply(y,1,function(x){x<-unlist(x); if (!is.na(x[2]) & x[2]=='2k' & !is.na(x[1]) & x[1]==' 1') 1 else 0} ) #you get the result you expect. #Also, note that your !is.na conditions are redundant for the given example because if the other conditions are true, the !is.na conditions default to true, as well. apply(y,1,function(x){x<-unlist(x); if (x[2]=='2k' & x[1]==' 1') 1 else 0} ) HTH, Daniel -- View this message in context: http://r.789695.n4.nabble.com/weird-apply-behavior-tp3777699p3778318.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.