2012-11-06 24 views
0
############ uncoded data 
    x10<- structure(c(0L, 0L, 0L, 0L, 1L, 1L, 1L, 5L, 8L, 9L, 31L, 1L, 
    0L, 0L, 0L, 1L, 0L, 1L, 2L, 7L, 2L, 10L, 0L, 2L, 0L, 2L, 2L, 
    5L, 2L, 4L, 6L, 8L, 4L, 1L, 1L, 3L, 2L, 2L, 6L, 1L, 12L, 18L, 
    7L, 29L, 8L, 4L, 6L, 8L, 6L, 19L, 3L, 9L, 12L, 3L, 12L, 14L, 
    1L, 2L, 1L, 3L, 1L, 0L, 4L, 6L, 3L, 11L, 0L, 0L, 0L, 1L, 3L, 
    7L, 5L, 8L, 21L, 26L, 51L, 0L, 1L, 0L, 3L, 5L, 10L, 9L, 29L, 
    55L, 60L, 125L, 3L, 0L, 1L, 1L, 3L, 10L, 1L, 6L, 18L, 17L, 13L, 
    6L, 3L, 4L, 13L, 6L, 33L, 17L, 48L, 84L, 54L, 103L, 34L, 11L, 
    20L, 27L, 26L, 50L, 29L, 30L, 54L, 28L, 34L, 31L, 5L, 7L, 3L, 
    4L, 20L, 8L, 16L, 16L, 8L, 41L, 1L, 0L, 0L, 3L, 1L, 3L, 3L, 11L, 
    19L, 16L, 56L, 0L, 0L, 0L, 0L, 3L, 11L, 3L, 18L, 25L, 21L, 62L, 
    3L, 0L, 1L, 4L, 2L, 7L, 8L, 15L, 22L, 12L, 19L, 5L, 2L, 8L, 9L, 
    9L, 42L, 18L, 51L, 70L, 45L, 103L, 29L, 15L, 23L, 34L, 25L, 57L, 
    23L, 38L, 55L, 30L, 33L, 36L, 5L, 5L, 6L, 6L, 16L, 6L, 10L, 17L, 
    9L, 35L, 2L, 0L, 1L, 1L, 2L, 4L, 6L, 8L, 22L, 33L, 73L, 0L, 0L, 
    0L, 1L, 2L, 7L, 7L, 15L, 27L, 21L, 56L, 1L, 2L, 2L, 0L, 2L, 9L, 
    4L, 8L, 24L, 13L, 17L, 14L, 2L, 8L, 10L, 16L, 51L, 16L, 51L, 
    69L, 29L, 99L, 44L, 18L, 25L, 34L, 19L, 49L, 26L, 43L, 63L, 15L, 
    30L, 42L, 9L, 17L, 7L, 3L, 16L, 8L, 13L, 22L, 18L, 45L, 0L, 0L, 
    1L, 3L, 0L, 7L, 4L, 14L, 15L, 20L, 47L, 0L, 1L, 0L, 1L, 1L, 3L, 
    3L, 5L, 6L, 11L, 21L, 1L, 0L, 0L, 4L, 2L, 3L, 8L, 7L, 17L, 3L, 
    13L, 5L, 2L, 6L, 13L, 15L, 34L, 19L, 42L, 62L, 37L, 83L, 52L, 
    16L, 26L, 26L, 29L, 53L, 28L, 45L, 45L, 15L, 22L, 26L, 8L, 12L, 
    11L, 5L, 12L, 5L, 7L, 17L, 10L, 28L), .Dim = c(11L, 6L, 5L), .Dimnames = structure(list(
     c("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), 
     c("I've changed for work/ a new job/ gone on a work plan", 
     "I want a phone that doesn't offer", "I want Best Mates/ Favourites", 
     "I was offered or saw a better offer on another network", 
     "Issues with the network (poor coverage)", "Other" 
     ), YearQuarter = c("2011-09-01", "2011-12-01", "2012-03-01", 
     "2012-06-01", "2012-09-01")), .Names = c("", "", "YearQuarter" 
    )), class = "table") 

############ recoded data 
x10 <- structure(c(40L, 3L, 13L, 12L, 3L, 9L, 12L, 13L, 10L, 36L, 16L, 
    30L, 15L, 54L, 21L, 14L, 22L, 10L, 77L, 16L, 29L, 185L, 28L, 
    84L, 30L, 19L, 24L, 157L, 82L, 132L, 62L, 197L, 84L, 49L, 78L, 
    32L, 72L, 11L, 30L, 83L, 17L, 43L, 31L, 25L, 37L, 148L, 93L, 
    121L, 63L, 206L, 93L, 44L, 80L, 27L, 106L, 16L, 30L, 77L, 17L, 
    42L, 30L, 20L, 32L, 128L, 117L, 120L, 45L, 215L, 106L, 63L, 102L, 
    35L, 67L, 15L, 29L, 32L, 9L, 11L, 16L, 18L, 24L, 120L, 94L, 104L, 
    37L, 230L, 90L, 38L, 79L, 24L), .Dim = c(3L, 6L, 5L), .Dimnames = structure(list(
     c("Promoters", "Detractors", "Passive"), c("I've changed for work/ a new job/ gone on a work plan", 
     "I want a phone that doesn't offer", "I want Best Mates/ Favourites", 
     "I was offered or saw a better offer on another network", 
     "Issues with the network (poor coverage)", "Other" 
     ), YearQuarter = c("2011-09-01", "2011-12-01", "2012-03-01", 
     "2012-06-01", "2012-09-01")), .Names = c("", "", "YearQuarter" 
    )), class = "table") 


    x10.p <- round(prop.table(x10,c(3,2)),2)*100 

您好淨促進得分如何制定出由prop.table()

淨促進得分是詢問消費者打分「的可能性,以推薦產品或服務問題'在零到十的範圍內。以10人和9人報道的人被稱爲「促銷員」,被評爲8被評爲「被動」的人,被報告少於6人的人被視爲反對者。淨促銷得分是'促銷人'的百分比減去'反對者'的百分比之差。

從2011年9月到2012年9月,我將這個問題的答案彙總並記錄在表格x10中。這些數字是每個組的實際人數(發起者,評估者和被動者)。對於三維表格我抱歉,我對每個理由都有興趣得到網絡促銷員分數(例如,9月份發起人和反對者之間因「工作變化/新工作/去過工作計劃」的百分比差異是多少2012年

淨促進得分之前,我可以繪製它需要一個位操作。我不知道是否有人知道該怎麼做呢?

乾杯

+0

這可能會更容易,如果你製作表格出它之前重新編碼數據... someething像'ifelse(yourData> = 9,1,ifelse(yourData <= 6,-1,0) )'。然後只需要你的數據的sum()。 – Chase

回答

1

一,不圓,直到你完成所有的計算(否則你將百分比不加1)

x10.p <- prop.table(x10,c(3,2))*100 

# get the total promoters 
promoters <- apply(x10.p, 2:3, function(x) sum(tail(x,2))) 
# and detractors 
detractors <- apply(x10.p, 2:3, function(x) sum(head(x,7))) 
# passive is everything else 
passive <- passive <- 100 - (detractors +promoters) 
# the net score 
net <- promoters - detractors 

net 

                 YearQuarter 
                 2011-09-01 2011-12-01 2012-03-01 2012-06-01 2012-09-01 
    I've changed for work/ a new job/ gone on a work plan 66.071429 50.00000 53.982301 59.210526 46.846847 
    I want a phone that doesn't offer      37.500000 52.86195 46.153846 44.117647 44.230769 
    I want Best Mates/ Favourites       -2.857143 15.06849 6.451613 12.195122 -3.448276 
    I was offered or saw a better offer on another network 24.390244 20.21563 15.193370 3.013699 8.176101 
    Issues with the network (poor coverage)    -43.333333 -39.35860 -39.502762 -46.448087 -54.061625 
    Other             -17.391304 -18.23899 -23.841060 -19.500000 -29.078014 

您希望2012年9月選擇該列,並使用drop = FALSE確保它仍然是1列的矩陣。

net[,'2012-09-01', drop = FALSE] 
                 YearQuarter 
                 2012-09-01 
    I've changed for work/ a new job/ gone on a work plan 46.846847 
    I want a phone that doesn't offer      44.230769 
    I want Best Mates/ Favourites       -3.448276 
    I was offered or saw a better offer on another network 8.176101 
    Issues with the network (poor coverage)    -54.061625 
    Other             -29.078014 
+0

非常聰明。如何制定被動(被人們報告7和8) 被動< - apply(x10.p,2:3,function(x)sum(tail(x,3,2))) –

+0

100-(被動+批評者)。添加到我的示例中 – mnel