這個數據幀開始如何使R函數返回多個列並將它們附加到數據框?
myDF = structure(list(Value = c(-2, -1, 0, 1, 2)), .Names = "Value", row.names = c(NA, 5L), class = "data.frame")
假設我要上運行的是myDF $價值
getNumberInfo <- function(x) {
if(x %% 2 ==0) evenness = "Even" else evenness="Odd"
if(x > 0) positivity = "Positive" else positivity = "NonPositive"
if (positivity == "Positive") logX = log(x) else logX=NA
c(evenness,positivity,logX)
}
...每一行這個函數來得到這個數據幀
structure(list(Value = c(-2, -1, 0, 1, 2), Evenness = c("Even",
"Odd", "Even", "Odd", "Even"), Positivity = c("NonPositive",
"NonPositive", "NonPositive", "Positive", "Positive"), Log = c(NA,
NA, NA, "0", "0.693147180559945")), row.names = c(NA, 5L), .Names = c("Value",
"Evenness", "Positivity", "Log"), class = "data.frame")
't(sapply'do)與'tapply'相反嗎?我不知道用't()'包裝什麼東西,我從來沒有見過它。 – 2016-10-09 00:11:58