I want to create multiple dataframes based on values in a column.
sample data
df Index Product ID Amount 200 Prod1 01 100 201 Prod1 01 150 202 Prod1 01 123 203 Prod1 01 123 204 Prod1 02 110 205 Prod1 02 175 206 Prod1 02 190 207 Prod2 03 120 208 Prod2 03 135 209 Prod2 03 150
I would like to add a column as Base for each ID. The value of Base is the first amount value in each ID.
>df1
Index Product ID Amount Base
200 Prod1 01 100 100
201 Prod1 01 150 100
202 Prod1 01 123 100
203 Prod1 01 123 100
204 Prod1 02 110 110
205 Prod1 02 175 110
206 Prod1 02 190 110
207 Prod2 03 120 120
208 Prod2 03 135 120
209 Prod2 03 150 120
I am thinking of subset the df by ID first. Just wondering if any way to do this?
do.call(rbind.data.frame, lapply(split(df, df$ID), function(sset) within(sset, Base <- Amount[1])))Amountvalue that appears or the minimumAmountvalue to be put inBasecolumn?