Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.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
使用dplyr查找会话中是否出现页面/请求id_R_Dplyr_Match - Fatal编程技术网

使用dplyr查找会话中是否出现页面/请求id

使用dplyr查找会话中是否出现页面/请求id,r,dplyr,match,R,Dplyr,Match,我有一个工作DF: lf3 = structure(list(session_id = c(1L, 1L, 1L, 2L, 3L, 3L, 4L, 4L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 11L, 12L, 12L, 12L, 13L, 13L, 14L), userId = c(1, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9

我有一个工作DF:

lf3 = structure(list(session_id = c(1L, 1L, 1L, 2L, 3L, 3L, 4L, 4L, 
5L, 6L, 6L, 6L, 6L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 
11L, 12L, 12L, 12L, 13L, 13L, 14L), userId = c(1, 1, 1, 2, 3, 
3, 4, 4, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 11, 12, 
12, 12, 13, 13, 14), datetime = structure(c(1457029336, 1457029337, 
1457029340, 1457029596, 1457030783, 1457030784, 1457030918, 1457030920, 
1457031472, 1457031674, 1457031675, 1457031677, 1457031678, 1457032116, 
1457032117, 1457032963, 1457032964, 1457032966, 1457032967, 1457033246, 
1457033247, 1457033249, 1457033359, 1457033530, 1457034351, 1457034353, 
1457034356, 1457034623, 1457034624, 1457035397), class = c("POSIXct", 
"POSIXt"), tzone = "UTC"), referer = c(22, 2, 6, 20, 21, 6, 23, 
17, 21, 22, 11, 10, 6, 24, 10, 6, 25, 26, 27, 8, 6, 1, 6, 28, 
29, 30, 31, 6, 30, 32), request = c(1, 2, 3, 4, 5, 6, 7, 8, 5, 
9, 6, 10, 10, 9, 6, 11, 9, 12, 13, 8, 3, 9, 3, 14, 13, 11, 15, 
6, 6, 16)), .Names = c("session_id", "userId", "datetime", "referer", 
"request"), row.names = c(NA, 30L), class = "data.frame")
现在,我正在寻找某些请求ID,以匹配它们是否在会话中,以及它们是否返回数据帧中的位置索引

我正在尝试此代码,但不知何故没有获得任何成功:

lf3 %>% group_by(session_id) %>% do(.,match(6,.,request))

检查request=6是否在会话中,并返回位置索引(执行每个会话)

我认为此代码将打印您所需的输出:-

“as.numeric(行名(lf3[ifelse(lf3$session_id==6,T,F),])”

这是一个选项:

lf3 %>% group_by(session_id) %>% 
                      summarise(do_match = 6 %in% request,
                      act_match = ifelse(6 %in% request,which(request==6),0))

请注意,一个请求可能在一个会话中出现两次(这仅捕获第一次)

请详细说明
的含义,如果它们在会话中或不在会话中
请显示预期的输出I只需要它的索引位置,如果它在会话中存在(真或假)然后稍后我将进行求和,以找出包含该页面ID/请求的会话数。假设我们检查6,它位于具有不同ID的多个会话中,现在我想使用do函数返回该元素的相对索引位置,但无法成功。请使用预期答案更新您的帖子,还是没有?