[R] using nested ifelse when i want to process values from more than 3 columns of data frame

Indhira, Anusha Anusha.Indhira at controlsdata.com
Mon Oct 24 13:56:25 CEST 2016


I would like to process each row of data frame having 8 columns of which I am interested in 4 columns for my analysis.I tried using apply function but I get syntax error,although I checked for missing syntaxes ,couldn't figure out the mistake.Can you also suggest me more efficient way to perform same action.

# creating target column from result
kdata$target <- apply(kdata,1,ifelse((kdata$H1 & kdata$H2 & kdata$H3 &
                                                         kdata$H8) == 1,"all-true",(ifelse(kdata$H1== 0 &
                                                                                                            kdata$H2 == 0 &
                                                                                                            kdata$H3 == 0 &
                                                                                                            kdata$H8 == 0) ,
This e-mail (including attachments) contains contents owned by Rolls-Royce plc and its subsidiaries, affiliated companies or customers and covered by the laws of England and Wales, Brazil, US, or Canada (federal, state or provincial). The information is intended to be confidential and may be legally privileged. If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, interception or copying of this communication is strictly prohibited and may subject you to further legal action. Reply to the sender if you received this email by accident, and then delete the email and any attachments.

	[[alternative HTML version deleted]]

More information about the R-help mailing list