[R] Proper 3rd and 4th Parameters for my oOut() function
khobson@fd9ns01.okladot.state.ok.us
khobson at fd9ns01.okladot.state.ok.us
Wed May 11 17:29:45 CEST 2005
How can I pass the column names for XX and YY to my funcition properly?
If I change T314 column names to X and Y and use those in the function
call, it works properly. Labs 1, 2, 3, and 25 are eliminated in T314.out.
####### R code starts here.
rm(list=ls())
# Data from NCHRP Appendix A -
http://trb.org/publications/nchrp/nchrp_w71.pdf
T314 <- structure(list(Lab = as.integer(c(1:60)), XX = c(4.89, 3.82, 2.57,
2.3,2.034, 2, 1.97, 1.85,1.85, 1.85, 1.84, 1.82, 1.82, 1.77, 1.76, 1.67,
1.66,
1.63, 1.62,1.62, 1.55, 1.54, 1.54, 1.53, 1.53, 1.44, 1.428, 1.42, 1.39,
1.36,
1.35, 1.31, 1.28, 1.24, 1.24, 1.23, 1.22, 1.21, 1.19, 1.18, 1.18, 1.18,
1.17,
1.16, 1.13, 1.13, 1.099, 1.09, 1.09, 1.08, 1.07, 1.05, 0.98, 0.97, 0.84,
0.808,
0.69, 0.63, 0.6, 0.5), YY = c(5.28, 3.82, 2.41, 2.32, 2.211, 1.46, 2.24,
1.91,
1.78, 1.63, 1.81, 1.92, 1.2, 1.67, 1.28, 1.59, 1.45, 2.06, 1.91, 1.19,
1.26,
1.79, 1.39, 1.48, 0.72, 1.29, 1.517, 1.71, 1.12, 1.38, 0.93, 1.36, 1.2,
1.23,
0.71, 1.29, 1.26, 1.48, 1.26, 1.33, 1.21, 1.04, 1.57, 1.42, 1.08, 1.04,
1.33,
1.33, 1.2, 1.05, 1.24, 0.91, 0.99, 1.06, 1.27, 0.702, 0.77, 0.58, 1,
0.38)),
.Names = c("Lab", "XX", "YY" ), class = "data.frame",
row.names = as.character(c(1:60)))
### Be sure to remove NA data prior to oOut()
oOut <- function(dsin, dsout, X, Y)
{
oOutsub <- function(olimit){
# Get Medians for Invalid Data Determination
Xmed <- median(dsin$X); Ymed <- median(dsin$Y)
# Make new dataset with (Y-X)-(Ymedian-Xmedian) column
dsout <- cbind(dsin, XY=(dsin$Y-dsin$X)-(Ymed-Xmed))
# Get median for new column
XYmed <- median(dsout$XY)
iqx <- diff(quantile(dsin$X, c(0.125, .875)))
iqy <- diff(quantile(dsin$Y, c(0.125, .875)))
iqxy <- diff(quantile(dsout$XY, c(0.125, .875)))
# Invalid Upper Limits
iulX <- quantile(dsin$X, 0.875)+olimit*iqx
iulY <- quantile(dsin$Y, 0.875)+olimit*iqy
iulXY <- quantile(dsout$XY, 0.875)+olimit*iqxy
# Invalid Lower Limits
illX <- quantile(dsin$X, 0.125)-olimit*iqx
illY <- quantile(dsin$Y, 0.125)-olimit*iqy
illXY <- quantile(dsout$XY, 0.125)-olimit*iqxy
dsout <- subset(dsout, with(dsout, X <= iulX & X >= illX))
dsout <- subset(dsout, with(dsout, Y <= iulY & Y >= illY))
dsout <- subset(dsout, with(dsout, XY <= iulXY & XY >= illXY))
dsout
}
dsout <- oOutsub(1.555) #Eliminates Invalid Data
dsin <- dsout
dsout <- oOutsub(0.674) #Eliminates Outlier Data
dsout <- dsout[1:(ncol(dsout)-2)] #Trim outer 2 XY columns
dsout
}
T314.PP4 <- oOut(T314, T314.PP4, XX, YY)
T314.PP4 # showing resutls.
mailto:khobson at odot.org
Kenneth Ray Hobson, P.E.
Oklahoma DOT - QA & IAS Manager
200 N.E. 21st Street
Oklahoma City, OK 73105-3204
(405) 522-4985, (405) 522-0552 fax
Visit our website at:
http://www.okladot.state.ok.us/materials/materials.htm
More information about the R-help
mailing list