~/ learn/ afm-112/ cards/ "Of Ontario's sales" vs "of online sales"
1 of 9

In R, type the call that shows each province's sales split across channels as row percentages to 1 dp.

In R, type the call that shows each province's sales split across channels as row percentages to 1 dp.

Answer

round(prop.table(xtabs(amount ~ prov + channel, data = orders), 1) * 100, 1)

xtabs makes the sum grid; prop.table with margin 1 divides each cell by its row total; ON reads 46.6 / 53.4. Margin 2 would be columns.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/b0cda475-e869-49ae-895d-63b5b1ab9b3f/flashcard utf-8 LF