This code doesn't work, independently of RStudio. When you type j[i]
then R considers the i
-th element of j
, but j
is not defined. Define it before:
mean.dataframe = function (df)
{
j = rep(NA,ncol(df))
for (i in 1:ncol(df))
{
j[i]= mean(df[[i]])
}
print (j)
}