Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中每个客户的日期计数_R - Fatal编程技术网

R中每个客户的日期计数

R中每个客户的日期计数,r,R,对于以下数据 custid <- c(1,1,1,2,2,5,6,8,8,8) date <- c(20130401, 20130403, 20130504, 20130508, 20130511, 20130716, 20130719, 20130423, 20130729, 20130707) money <- c(1, 2, 45, 3.56, 32.39, 1, 2, 3.90, 4, 8.5) file <- d

对于以下数据

custid <- c(1,1,1,2,2,5,6,8,8,8)

date <- c(20130401,  20130403,  20130504,   20130508,   20130511,   20130716,   
      20130719, 20130423,   20130729,   20130707) 

money <- c(1, 2, 45, 3.56, 32.39, 1, 2, 3.90, 4, 8.5)

file <- data.frame(custid, date, money)
你可以试试

 aggregate(cbind(Trans_count=date)~custid, file, length)

或者如果您需要向量输出

table(file$custid)
library(data.table)
setDT(file)[, list(Trans_count=.N), .(custid)]
library(dplyr)
file %>% 
    group_by(custid) %>% 
    summarise(Trans_count=n())
table(file$custid)