~/ learn/ afm-112/ cards/ df$new <- …, names(), <- NULL
1 of 9

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/4e0c67ae-6c86-440c-8189-f4c400d330d8/flashcard utf-8 LF