11 Multiple arguments
11.1 Function with two arguments
- Function with mandatory and default arguments
11.2 Data
11.3 Call with mandatory argument
Code
fn_mean(A)
[1] 14
Code
fn_mean(B)
[1] NA
11.4 Call with mandatory and default arguments
Code
fn_mean(B, na_rm = TRUE)
[1] 14.75
11.5 Function with two arguments
Code
def fn_mean(x, na_rm=False):
if na_rm:
= x[~np.isnan(x)]
x
= len(x)
xn = np.sum(x)
xsum
= xsum / xn
xmean
print('\nMean =', xmean)
return xmean
# Example usage:
= np.array([11, 12, np.nan, 14, 15])
A =True)
fn_mean(A, na_rm=False) fn_mean(A, na_rm