1
我試圖重寫這段代碼(學習這種做法),用%>%操作:重寫代碼%>%操作
library(arules)
data(AdultUCI) #https://archive.ics.uci.edu/ml/datasets/Census+Income
AdultUCI[["capital-gain"]] <- ordered(cut(AdultUCI[["capital-gain"]],
+ c(-Inf, 0, median(AdultUCI[["capital-gain"]][AdultUCI
+ [["capital-gain"]] > 0]), Inf)),
+ labels = c("None", "Low", "High"))
是否有可能呢?這裏是我的嘗試:
AdultUCI[["capital-gain"]] <- ordered %>% cut %>% AdultUCI[["capital-gain"]],
+ c(-Inf, 0, median(AdultUCI[["capital-gain"]][AdultUCI[["capital-gain"]] > 0]),
+ Inf),labels = c("None", "Low", "High")
請讓你的代碼** [重複性(http://stackoverflow.com/a/28481250/2725969)**。 – BrodieG
一般而言,您幾乎總是可以用管道運算符替換嵌套函數。你有什麼嘗試?它沒有工作?有什麼問題? – Molx
@Molx我解決這個漫長的操作有問題。訂單是正確的?大部分%>%? – Kulis