~/ learn/ afm-112/ cards/ Two-way flags and bands, vectorised
1 of 8

In R, type the line that adds a level column to orders — "High" where amount is at least 500, otherwise "Low".

In R, type the line that adds a level column to orders — "High" where amount is at least 500, otherwise "Low".

Answer

orderslevel <- ifelse(ordersamount >= 500, "High", "Low")

Condition, value if TRUE, value if FALSE — all twelve rows in one call. table(orders$level) is High 5, Low 7; the column is character, not factor.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/1d637167-c58d-497c-a60f-505e5466101d/flashcard utf-8 LF