0
我嘗試使用我自己的函數使用apply函數。不過,我不斷收到此錯誤:在match.fun錯誤(FUN): 'calculate_3month_average_volume(volume_matrix,90)' 不低於在用戶定義函數R中應用()
代碼的功能,字符或符號:
#Calculate 3 monthtly average volume (does not work, coding issue)
calculate_3month_average_volume <- function(stock, number_of_days){
return(SMA(stock, number_of_days))
}
avg_volume_matrix <- apply(X = volume_matrix, MARGIN = 2, FUN = calculate_3month_average_volume(volume_matrix,90))
嘗試:'申請(X = volume_matrix,MARGIN = 2,FUN = calculate_3month_average_volume,volume_matrix,90)' – Gopala
@ user3949008這給了我錯誤:在FUN(newX [,i],...)中出錯:未使用的參數(90) –
Oooops ...卷矩陣已經是一個參數。所以,你應該只是通過number_of_days = 90。看看這個:http://stackoverflow.com/questions/14427253/passing-several-arguments-to-fun-of-lapply-and-others-apply – Gopala