我有一個數據幀提取出位置索引且請求對得到匹配/在Web訪問會話發生
lf = structure(list(session_id = c(48L, 48L, 48L, 48L, 48L, 48L, 54L,
54L, 54L, 54L, 54L, 54L, 72L, 72L, 72L, 72L, 72L, 74L, 74L, 74L,
74L, 74L, 78L, 78L, 78L, 78L, 78L, 90L, 90L, 90L), datetime = structure(c(1457050110,
1457050111, 1457050112, 1457050114, 1457050117, 1457050118, 1457052045,
1457052048, 1457052050, 1457052051, 1457052052, 1457052054, 1457057067,
1457057067, 1457057067, 1457057070, 1457057071, 1457058143, 1457058143,
1457058144, 1457058149, 1457058150, 1457059193, 1457059193, 1457059195,
1457059198, 1457059199, 1457063485, 1457063486, 1457063486), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), request = c(7, 7, 14, 20, 9, 4, 9,
1, 12, 20, 6, 12, 4, 15, 8, 8, 12, 10, 6, 6, 13, 1, 5, 6, 20,
1, 8, 3, 6, 13)), .Names = c("session_id", "datetime", "request"
), row.names = c(NA, -30L), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"))
現在,我檢查了一定對請求(REQ1,REQ2)的這個子集匹配或者不在給定的數據框中,如果匹配,則獲取匹配發生的位置索引。
我使用這段代碼: -
lf1 = lf %>% group_by(session_id) %>% do(positions = match(c(1,6),.$request))
正如你看到的我正在要求對(1,6)爲示範目的的實例。
所需的輸出: -
如果可能的話,我想篩選出那些session_ids了來港。因此,同時具有匹配位置1和位置2只session_ids切不可NA
是子集(lf1,!any(is.na(positions)))'你需要什麼? –
您是否認爲通過運行lf1代碼可以看到'lf%>%group_by(session_id)%>%filter(all(!is.na(match(c(1,6),request))))' – akrun
如果從lf1%>%mutate(position1 = someCodeToFetchPos1,position2 = FetchPos2) – SumitArya