~/ learn/ afm-112/ cards/ Data Preparation in R
1 of 67

In R, type the one line that adds a share column to orders — each amount as a fraction of the quarter's total amount.

In R, type the one line that adds a share column to orders — each amount as a fraction of the quarter's total amount.

Answer

ordersshare <- ordersamount / sum(orders$amount)

Assigning to a column name that does not exist creates it. sum() is one number recycled against all twelve; order 1005 gets 1320 / 6140 = 0.2149837.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/f73888b7-c56e-4e95-966b-e1e7945340e6/flashcard utf-8 LF