sedit {Hmisc}R Documentation

Character String Editing and Miscellaneous Character Handling Functions

Description

This suite of functions was written to implement many of the features of the UNIX sed program entirely within S-PLUS (function sedit). The substring.location function returns the first and last position numbers that a sub-string occupiularly ged values abline(0,1) # unique values unjittered on abline points(x+0.1, jitter2(x, limit=FALSE), col=2) # allow locally maximum jittering points(x+0.2, jitter2(x, fill=1), col=3); abline(h=seq(0.5,9,1), lty=2) # fill 3/3 instead of 1/3 x <- rnorm(200,0,2)+1; y <- x^2 x2 <- round((x+rnorm(200))/2)*2 x3 <- round((x+rnorm(200))/4)*4 dfram <- data.frame(y,x,x2,x3) plot(dfram$x2, dfram$y) # jitter2 via scat1d scat1d(dfram$x2, y=dfram$y, preserve=TRUE, col=2) scat1d(dfram$x2, preserve=TRUE, frac=-0.02, col=2) scat1d(dfram$y, 4, preserve=TRUE, frac=-0.02, col=2) pairs(jitter2(dfram)) # pairs for jittered data.frame # This gets reasonable pairwise scatter plots for all combinations of # variables where # # - continuous variables (with unique values) are not jittered at all, thus # all relations between continuous variables are shown as they are, # extreme values have exact positions. # # - discrete variables get a reasonable amount of jittering, whether they # have 2, 3, 5, 10, 20 ... levels # # - different from adding noise, jitter2() will use the available space # optimally and no value will randomly mask another # # If you want a scatterplot with lowess smooths on the *exact* values and # the point clouds shown jittered, you just need # pairs( dfram ,panel=function(x,y) { points(jitter2(x),jitter2(y)) lines(lowess(x,y)) } ) datadensity(dfram) # graphical snapshot of entire data frame datadensity(dfram, group=cut2(dfram$x2,g=3)) # stratify points and frequencies by # x2 tertiles and use 3 colors # datadensity.data.frame(split(x, grouping.variable)) # need to explicitly invoke datadensity.data.frame when the # first argument is a list


[Package Hmisc version 3.1-2 Index]
./usr/lib/R/site-library/Hmisc/html/score.binary.html0000644000000000000000000000754210517346147021412 0ustar rootroot R: Score a Series of Binary Variables
score.binary {Hmisc}R Documentation

Score a Series of Binary Variables

Description

Creates a new variable from a series of logical conditions. The new variable can be a hierarchical category or score derived from considering the rightmost TRUE value among the input variables, an additive point score, a union, or any of several others by specifying a function using the fun argument.

Usage

score.binary(..., fun=max, points=1:p, 
             na.rm=funtext == "max", retfactor=TRUE)

Arguments

... a list of variables or expressions which are considered to be binary or logical
fun a function to compute on each row of the matrix represented by a specific observation of all the variables in ...
points points to assign to successive elements of ... . The default is 1, 2, ..., p, where p is the number of elements. If you specify one number for points, that number will be duplicated (i.e., equal weights are assumed).
na.rm set to TRUE to remove NAs from consideration when processing each row of the matrix of variables in ... . For fun=max, na.rm=TRUE is the default since score.binary assumes that a hierarchical scale is based on available information. Otherwise, na.rm=FALSE is assumed. For fun=mean you may want to specify na.rm=TRUE.
retfactor applies if fun=max, in which case retfactor=TRUE makes score.binary return a factor object since a hierarchical scale implies a unique choice.

Value

a factor object if retfactor=TRUE and fun=max or a numeric vector otherwise. Will not contain NAs if na.rm=TRUE unless every variable in a row is NA. If a factor object is returned, it has levels "none" followed by character string versions of the arguments given in ... .

See Also

any, sum, max, factor

Examples

set.seed(1)
age <- rnorm(25, 70, 15)
previous.disease <- sample(0:1, 25, TRUE)
#Hierarchical scale, highest of 1:age>70  2:previous.disease
score.binary(age>70, previous.disease, retfactor=FALSE)
#Same as above but return factor variable with levels "none" "age>70" 
# "previous.disease"
score.binary(age>70, previous.disease)

#Additive scale with weights 1:age>70  2:previous.disease
score.binary(age>70, previous.disease, fun=sum)
#Additive scale, equal weights
score.binary(age>70, previous.disease, fun=sum, points=c(1,1))
#Same as saying points=1

#Union of variables, to create a new binary variable
score.binary(age>70, previous.disease, fun=any)

[Package Hmisc version 3.1-2 Index]
./usr/lib/R/site-library/Hmisc/html/sedit.html0000644000000000000000000002035110517346147020115 0ustar rootroot R: Character String Editing and Miscellaneous Character Handling Functions