我想這個函數返回結果(數字)和文本。如何從函數返回結果和書面聲明?
sum_of_squares_cubes <- function(x,y) {
sq = x^2 + y^2
cube = x^3 + y^3
return(list(sq, cube))
cat("The sum of squares is", sq, "\n" ,
"The sum of cubes is", cube, "\n" ,
)
}
這樣做只會返回結果的編號。
所需的輸出:
sum_of_squares_cubes(2,3)
13
35
"The sum of squares is 13"
"The sum of cubes is 35"
把'return'聲明cat' – Gabe
使用列表後'.. ... –
'return()'後面沒有執行代碼。如果您想要打印,請放上'cat()'。 – HubertL