I need assistance with identifying an effective approach in R for conditionally assigning values to a new column in a data matrix after testing to see if specific string exist in two columns. I am using R Studio for these manipulations (I would characterize my skills with R under the "working knowledge" thereof).
I experimented with an admittedly verbose series of if() else() statements with each containing two conditions. Unfortunately, the result in R Studio is "There were [x number] of warnings (use warnings()..." or "...the condition has length > 1 and only the first element will be used." I couldn't find a solution on my own (or after reading various forum posts that expressed similar issues).
My data matrix looks something like this in the R Studio console:
I want to add a new example column called "Tag" and so I tried something like the following:
>exampleTable["Tag"] <- if(exampleTable$Subject == "Subject 1" & exampleTable$Author = "Eminem"){"Tag 1"} else if (exampleTable$Subject == "Subject 1" & exampleTable$Author = "Freddie Mac"){"Tag 2"}
Ideally, a working solution would successfully test for the existence of specific string in the "Subject" and "Author" columns and the result would be the new "Tag" column with whatever new string we wanted to add such as "Tag 1", "Tag 2", etc.
I understand the example above doesn't work so what is a better approach to do this? Thanks!