以下数据框包含有关营销广告系列的数据。
Sl No Success_Percentage communication_type Message
1 35.46666667 email Hello, Buy New Product
2 32.32830821 email Hi Buy New Product
3 22.9226361 SMS Hello World
4 21.88888889 SMS Hello, Buy New Product
5 40.04085802 FB Hi Buy New Product
6 38.7283237 FB Hello World
我希望按如下方式创建一个表。
Success_Percentage communication_type Message
22.9226361 SMS Hello World
21.88888889 SMS Hello, Buy New Product
35.46666667 email Hello, Buy New Product
32.32830821 email Hi Buy New Product
40.04085802 FB Hi Buy New Product
38.7283237 FB Hello World
我使用了dplyr包来实现子集。
require(dplyr)
dataframe%>%
group_by(communication_type, Message)
summarise_all(order(Success_Percentage))
我无法获得上述输出。请注意,Success%是随机混合的(不是按此处的线性顺序) 我无法获得所需的输出。
答案 0 :(得分:1)
在您的新表中,您似乎希望根据communication_type
安排表格,并且在每个communication_type
内,您希望按降序排列Success_Percentage
。< / p>
您的数据集:
df <- structure(list(Sl_No = 1:6, Success_Percentage = c(35.46666667,
32.32830821, 22.9226361, 21.88888889, 40.04085802, 38.7283237
), communication_type = c("email", "email", "SMS", "SMS", "FB",
"FB"), Message = c("Hello, Buy New Product", "Hi Buy New Product",
"Hello World", "Hello, Buy New Product", "Hi Buy New Product",
"Hello World")), class = "data.frame", .Names = c("Sl_No", "Success_Percentage",
"communication_type", "Message"), row.names = c(NA, -6L))
按communication_type
,SMS
和email
的顺序生成因子FB
;并相应安排:
df %>%
mutate(communication_type = factor(communication_type, levels = c("SMS", "email", "FB"))) %>%
arrange(communication_type, desc(Success_Percentage))