Displaying 2 results from an estimated 2 matches for "mydataf".
Did you mean:
mydata
2013 Nov 22
1
Use of 'by' function with FUN=mean
Hi everybody
I'm having some unexpected errors from the 'by' function when using it to
apply the mean function (by a factor) to a dataframe of numerical
variables. The following piece of toy code demonstrates:
myDataF<-warpbreaks
myDataF$X<-runif(54) # creating an additional numerical variable in
warpbreaks for purposes of this demo
by(myDataF[,c("X","breaks")],myDataF[,"tension"],FUN=mean)
In R3.0.1 & R3.0.2 (run on Windows 7) this gives the following error
myDataF[, &...
2012 Oct 16
2
List of Levels for all Factor variables
...uot;S": 1 1 1 1 2 1 1 1 1 2 ...
$ COVERED_DP : int 2 2 4 0 1 3 1 2 0 0 ...
$ YRS_IN_SERIES : int 13 29 16 26 18 9 19 3 7 26 ...
$ SAVINGS_PCT : int 10 0 6 19 8 0 10 15 15 18 ...
$ Generation : Factor w/ 4 levels "Baby Boomers",..: 1 1 2 1 1 1 1 2 2 1 ...
2. Create mydataF to only include factor variables (and exclude NAME which I am not interested in)
> mydataF<-mydata[,sapply(mydata,function(x)is.factor(x))][,-1]
3. Get a list of all levels
> sapply(mydataF,function(x)levels(x))
$APPT_TYP_CD_LL
[1] "FX" "IN" "IP"
$ORG_...