16 Global Assignment
16.1 Global assigment of an object
16.2 Data
Code
A = c(NA, 12, 15, 14, 18)
16.3 Function call
Code
y = 5
fn_xmean(A, y = y, na.rm = TRUE)
$y
[1] 25
$xmean
[1] 14.75
Code
y
[1] 25
16.4 Global assignment of an object
Code
def fn_mean(x, **kwargs):
global y
= y**2
y
= kwargs.get('na_rm', None)
na_rm
if na_rm:
= x[~np.isnan(x)]
x
= len(x)
xn = np.sum(x)
xsum = xsum / xn
xmean return xmean
# Example usage:
= np.array([11, 12, np.nan, 14, 15])
A = 5
y =True)
fn_mean(A, na_rmprint(y)