Well done! You can use multiple columns in conditions. Consider this example: You want to create a column named
clean_ownership in the
houses data frame that indicates whether a particular property's paperwork is in order.
Here are the conditions we'll use for creating this column:
- The column is populated with "Yes" if
ownership_licence are all marked with "Y".
clean_ownership should be populated with "No".
First, we'll create the new
clean_ownership column and populate it with an initial value of "No" for all rows:
houses$clean_ownership <- "No"
Afterwards, we'll overwrite "No" with "Yes" for rows that satisfy the clean ownership conditions:
houses$usage_permit == "Y" &
houses$building_permit == "Y" &
houses$ownership_licence == "Y",]$clean_ownership <- "Yes"