Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://svn.r-project.org/R/branches/R-0-61-patches@896 00db46b3-68df-0310-9c12-caf00c1e9a41
- Loading branch information
pd
committed
Mar 13, 1998
1 parent
81368a8
commit d630cc7
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
subset.data.frame <- | ||
function (dfr, subset, select) | ||
{ | ||
if(missing(subset)) | ||
r<-NULL | ||
else { | ||
e <- substitute(subset) | ||
r <- eval(e,dfr) | ||
r <- r & !is.na(r) | ||
} | ||
if(missing(select)) | ||
vars<-NULL | ||
else { | ||
nl<-as.list(1:ncol(dfr)) | ||
names(nl)<-names(dfr) | ||
vars<-eval(substitute(select),nl) | ||
} | ||
dfr[r,vars,drop=F] | ||
} | ||
|
||
subset<- | ||
function(x,...) | ||
UseMethod("subset") | ||
|
||
subset.default <- | ||
function(x,subset) | ||
x[subset & !is.na(subset)] | ||
|
||
transform.data.frame <- | ||
function (dfr, ...) | ||
{ | ||
e <- eval(substitute(list(...)), dfr) | ||
tags <- names(e) | ||
inx <- match(tags, names(dfr)) | ||
matched <- !is.na(inx) | ||
if (any(matched)) { | ||
dfr[inx[matched]] <- e[matched] | ||
dfr<-data.frame(dfr) | ||
} | ||
if (!all(matched)) | ||
data.frame(dfr, e[!matched]) | ||
else dfr | ||
} | ||
|
||
transform <- | ||
function(x,...) | ||
UseMethod("transform") | ||
|
||
# Actually, I have no idea what to transform(), except dataframes. | ||
# The default converts its argument to a dataframe and transforms | ||
# that. This is probably marginally useful at best. --pd | ||
transform.default <- | ||
function(x,...) | ||
transform.data.frame(data.frame(x),...) |