要創建一些圖,我已經使用以下方法彙總了我的數據,其中包括所有需要的信息。取決於矢量的訂單清單
# Load Data
RawDataSet <- read.csv("http://pastebin.com/raw/VP6cF31A", sep=";")
# Load packages
library(plyr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(reshape2)
# summarising the data
new.df <- RawDataSet %>%
group_by(UserEmail,location,context) %>%
tally() %>%
mutate(n2 = n * c(1,-1)[(location=="NOT_WITHIN")+1L]) %>%
group_by(UserEmail,location) %>%
mutate(p = c(1,-1)[(location=="NOT_WITHIN")+1L] * n/sum(n))
通過一些其他分析,我確定了不同的用戶組。由於我想繪製我的數據,因此將繪圖以正確的順序顯示我的數據會很棒。 的順序是根據USEREMAIL和由以下定義:
order <- c("28","27","25","23","22","21","20","16","12","10","9","8","5","4","2","1","29","19","17","15","14","13","7","3","30","26","24","18","11","6")
問我new.df
與typeof(new.df)
的類型,它說,這是一個list
。我已經嘗試了一些方法,如order_by或with_order,但我直到現在我還沒有設法訂購我的new.df
,這取決於我的order
-vector。當然,訂單流程也可以在彙總部分完成。 有沒有辦法做到這一點?
只是'dplyr :: arrange'。 'typeof' data.frame是一個列表(它在技術上是); 'class'告訴你它是否實際上是一個'data.frame'。 – alistaire