>Dear S People:
>
>In R, there is a function str,
>which describes an object, by vector.
>
>Is there an equivalent in S +, please?
>
>S+ Version 6.2
>
>Windows
>Thanks.
>Sincerely,
>Laura Holt
>mailto: lauraholt_983@hotmail.com
Two possibilities for you to consider:
(1) Frank Harrell's Hmisc library has a "describe" function.
(2) The following function is useful for programming. It describes
the structure of an object (and says nothing about the values of
numbers stored in an object).
describeStructure _ function(x, maxlen=20, describeAttributes=T,
prefix="", attri=F){
# Describe the structure of object x, recursively.
# If x is a list of length longer than maxlen, only list the names of
# the components.
# If describeAttributes=F, then only give names of attributes.
# Prefix and attri are intended for internal use in recursive calls.
# If attri then attributes are being printed, use & instead of $ or @
# Tim Hesterberg <timh@insightful.com>, 2/18/2000, comments welcome.
#
# Determine attributes to be shown
ax _ attributes(x)
ax$dim _ NULL
ax$class _ NULL
if(is.list(x) || class(x) != "named") ax$names _ NULL
# Determine attributes to be shown separately
# -- none if !describeAttributes,
# -- otherwise everything but names and dimnames
if(describeAttributes){
ax1 _ ax[match(c("names","dimnames"), names(ax), nomatch=0)]
if(class(x) == "named") ax1$names _ NULL
ax2 _ ax
ax2$names _ NULL
ax2$dimnames _ NULL
}
else {
ax1 _ ax
ax2 _ NULL
}
ux _ unclass(x)
len _ length(ux)
if(!attri){
if(mode(x) == "numeric" && is.null(dim(x)) && len == 1)
cat(prefix,"scalar",sep="")
else if(is.null(x))
cat(prefix,"NULL")
else {
cat(prefix, mode(x),"[",sep="")
if(is.null(dim(x)))
cat(" length", len)
else
cat(dim(x),sep=",")
cat("]")
} # No end of line yet.
# List class after name of object
if(length(oldClass(x)))
cat(" oldClass:", oldClass(x),"\n")
else
cat(" class:", class(x),"\n")
}
# Attributes
if(length(ax1))
cat(prefix, "attributes:", names(ax1), "\n")
if(length(ax2))
Recall(ax2, maxlen, prefix = prefix, des=T, attri=T)
nn _ slotNames(x)
slotted _ length(nn) && !is.element(class(x), c("named", "structure"))
if(!slotted){
nn _ names(x)
if(is.null(nn)) nn _ 1:len
}
if(is.list(ux) && len){
if(len <= maxlen){
nn[nn==""] _ (1:len)[nn==""]
nn _ format.character(nn, justify="left")
for(i in 1:len){
cat(prefix,
if(attri) " &" else if(slotted) " @" else " $",
nn[i]," ",sep="")
Recall(ux[[i]], maxlen, prefix = paste(prefix," ",sep=""),
des=describeAttributes)
}
} else cat(prefix, "length > maxlen,",
if(!slotted && is.null(names(x))) "No names" else c("names=
",nn),
"\n")
}
invisible(NULL)
}
========================================================
| Tim Hesterberg Research Scientist |
| timh@insightful.com Insightful Corp. |
| (206)802-2319 1700 Westlake Ave. N, Suite 500 |
| (206)802-2500 (fax) Seattle, WA 98109-3044, U.S.A. |
| www.insightful.com/Hesterberg |
========================================================
Download the S+Resample library from www.insightful.com/downloads/libraries
I'll teach "Bootstrap Methods and Permutation Tests"
at the 2004 Insightful User Conference in Boston, Oct 19; see
http://www.insightful.com/news_events/2004uc
|