样品计算年龄
df <- data.frame(
Birth_Date = c("1952-03-21", "1963-12-20", "1956-02-25", "1974-08-04", "1963-06-13", "1956-11-20", "1974-03-07", "1963-10-23", "1952-11-24", "1974-12-16"),
Items_Amount = c(68,189,69,19,299,79,149,149,29,189)
)
df
我试图分析一个数据集,其中有跨90年列Item_Amount(以$)和客户的出生日期蔓延。目标是比较基于适当年龄组的销售百分比。
主要数据帧包含日期“出生日期”,从“1902年2月13日”到“1991年12月11日”的日期不是字符串列
'data.frame': 350241 obs. of 1 variable:
$ BirthDate: Date, format: "1964-06-08" "1964-06-08" "1964-06-08" "1964-06-08" ...
> min(Trans_Cust$Birth_Date)
[1] "1902-02-13"
> difftime(max(Trans_Cust$Birth_Date),min(Trans_Cust$Birth_Date),units = "auto")
Time difference of 32808 days
> max(Trans_Cust$Birth_Date)
[1] "1991-12-11"
如何找到立足现在年龄“Birth_Date”列,将其存储到新列“Present_ages”,然后继续计算由present_ages分组的sum(Items_Amount)
。
确保你提供了[可重现的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example )在寻求帮助的时候,这里的期望输出到底是什么?这几十年你想做什么? – MrFlick
@MrFlick详情添加了 –
你的mo相关问题涉及agegroup01 - agegroup09,但您对数据的描述表明您的数据跨越了10年。 – G5W