Suppose your data is called dfs:

dfs$NEW_COLUMN <- ifelse(dfs$A == dfs$C | dfs$B == dfs$C, "y", "n")

which says

if dfs column A equals dfs column C or dfs column B equals dfs column
C, put "y" else put "n"; then put the resulting vector into NEW_COLUMN
of dfs.

Note that if your data are factors, this won't work and you'll need to
wrap most things with as.character()

For more, see the manual "An Introduction to R" available to you by
typing help.start() at the interactive prompt.

Cheers,
Michael

On Tue, Aug 28, 2012 at 7:06 PM, Sapana Lohani <lohani.sap...@ymail.com> wrote:
> Hi, My data frame looks like
>
> A B C
>
> a b a
>
> x y z
>
>
> I want to add a new column which says "y" if either A or B matches with C and 
> "n" if there is no match. How can I do that?
>
> Thanks
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

______________________________________________
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.

Reply via email to