Displaying 1 result from an estimated 1 matches for "no_of_col".
2006 Oct 20
1
I really don't understand functions in R :-)
...ditional or looping to get what I really
need.
For instance, the example below calculates Cronbach's alpha
(actually, I found more elegant way in the www, and even package
psych that includes a function bringing identical results):
alfa<-function(df) {
not_empty_df<-df[ !is.na( df[ ,no_of_col<-length(vector<-c(1:(ncol
(df))))] )==TRUE , ]
no_of_variables<-ncol(not_empty_df)
no_of_cases<-nrow(not_empty_df)
var_covar<-var(not_empty_df,na.rm=T)
alfa<-(no_of_variables/(no_of_variables-1)*(1-sum(diag(var_covar))/sum
(var_covar)))
Alfa<-alfa
cat("Cronbach's alpha...