I have data frame which looks like this:

df=data.frame(
  eye_problemsdisorders_f6148_0_1=c(A,C,D,NA,D,A,C,NA,B,A),
  eye_problemsdisorders_f6148_0_2=c(B,C,NA,A,C,B,NA,NA,A,D),
  eye_problemsdisorders_f6148_0_3=c(C,A,D,D,B,A,NA,NA,A,B),
  eye_problemsdisorders_f6148_0_4=c(D,D,NA,B,A,C,NA,C,A,B),
  eye_problemsdisorders_f6148_0_5=c(C,C,NA,D,B,C,NA,D,D,B))

In reality I have much more columns and they don't always match
"eye_problemsdisorders_f6148" this string, and there is much more rows.

What I would like to do is create a new column, say named "case" where I
would have value "1" for every row where string "A" appears at least once
in any column, if not the value would be "0". So in the above example
column "case" would have these values: 1,1,1,1,0
Thanks
Ana

        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to