Re: [R] Tables: Invitation to make a collective package
If the functionality you are thinking of already exists across multiple packages an alternative to creating a new package would be to create a task view as in: http://cran.r-project.org/src/contrib/Views/ as explained in the ctv package and the article in R News 5/1. On 7/7/05, Jose Claudio Faria [EMAIL PROTECTED] wrote: Hi All, I would like to make an invitation to make a collective package with all functions related to TABLES. I know that there are many packages with these functions, the original idea is collect all this functions and to make a single package, because is arduous for the user know all this functions broadcast in many packages. So, I think that the original packages can continue with its original functions, but, is very good to know that exist one package with many (I dream all) the functions related to tables. I've been working with these functions (while I am learning R programming): ### # Tables - Package # ### # # 1. Tables # # # Common function # tb.make.table.I - function(x, start, end, h, right) { f- table(cut(x, br=seq(start, end, h), right=right)) # Absolut freq fr - f/length(x) # Relative freq frP - 100*(f/length(x)) # Relative freq, % fac - cumsum(f) # Cumulative freq facP - 100*(cumsum(f/length(x))) # Cumulative freq, % fi - round(f, 2) fr - round(as.numeric(fr), 2) frP - round(as.numeric(frP), 2) fac - round(as.numeric(fac), 2) facP - round(as.numeric(facP),2) res - data.frame(fi, fr, frP, fac, facP)# Make final table names(res) - c('Class limits', 'fi', 'fr', 'fr(%)', 'fac', 'fac(%)') return(res) } # # Common function # tb.make.table.II - function (x, k, breaks=c('Sturges', 'Scott', 'FD'), right=FALSE) { x - na.omit(x) # User defines only x and/or 'breaks' # (x, {k,}[breaks, right]) if (missing(k)) { brk - match.arg(breaks) switch(brk, Sturges = k - nclass.Sturges(x), Scott = k - nclass.scott(x), FD = k - nclass.FD(x)) tmp - range(x) start - tmp[1] - abs(tmp[2])/100 end - tmp[2] + abs(tmp[2])/100 R - end-start h - R/k } # User defines 'x' and 'k' # (x, k,[breaks, right]) else { tmp - range(x) start - tmp[1] - abs(tmp[2])/100 end - tmp[2] + abs(tmp[2])/100 R - end-start h - R/abs(k) } tbl - tb.make.table.I(x, start, end, h, right) return(tbl) } # # With Gabor Grotendieck suggestions (thanks Gabor, very much!) # tb.table - function(x, ...) UseMethod(tb.table) # # Table form vectors # tb.table.default - function(x, k, start, end, h, breaks=c('Sturges', 'Scott', 'FD'), right=FALSE) { # User defines nothing or not 'x' isn't numeric - stop stopifnot(is.numeric(x)) x - na.omit(x) # User defines only 'x' # (x, {k, start, end, h}, [breaks, right]) if (missing(k) missing(start) missing(end) missing(h) ) { brk - match.arg(breaks) switch(brk, Sturges = k - nclass.Sturges(x), Scott = k - nclass.scott(x), FD = k - nclass.FD(x)) tmp - range(x) start - tmp[1] - abs(tmp[2])/100 end - tmp[2] + abs(tmp[2])/100 R - end-start h - R/k } # User defines 'x' and 'k' # (x, k, {start, end, h}, [breaks, right]) else if (missing(start) missing(end) missing(h)) { stopifnot(length(k) = 1) tmp - range(x) start - tmp[1] - abs(tmp[2])/100 end - tmp[2] + abs(tmp[2])/100 R - end-start h - R/abs(k) } # User defines 'x', 'start' and 'end' # (x, {k,} start, end, {h,} [breaks, right]) else if (missing(k) missing(h)) { stopifnot(length(start) = 1, length(end) =1) tmp - range(x) R - end-start k - sqrt(abs(R)) if (k 5) k - 5 # min value of k h - R/k } # User defines 'x', 'start', 'end' and 'h' # (x, {k,} start, end, h, [breaks, right]) else if (missing(k)) { stopifnot(length(start) = 1, length(end) = 1, length(h) = 1) } else stop('Error, please, see the function sintax!') tbl - tb.make.table.I(x, start, end, h, right) return(tbl) } # # Table form data.frame # tb.table.data.frame - function(df, k, by, breaks=c('Sturges', 'Scott',
[R] Tables: Invitation to make a collective package
Hi All, I would like to make an invitation to make a collective package with all functions related to TABLES. I know that there are many packages with these functions, the original idea is collect all this functions and to make a single package, because is arduous for the user know all this functions broadcast in many packages. So, I think that the original packages can continue with its original functions, but, is very good to know that exist one package with many (I dream all) the functions related to tables. I've been working with these functions (while I am learning R programming): ### # Tables - Package # ### # # 1. Tables # # # Common function # tb.make.table.I - function(x, start, end, h, right) { f- table(cut(x, br=seq(start, end, h), right=right)) # Absolut freq fr - f/length(x) # Relative freq frP - 100*(f/length(x)) # Relative freq, % fac - cumsum(f) # Cumulative freq facP - 100*(cumsum(f/length(x))) # Cumulative freq, % fi - round(f, 2) fr - round(as.numeric(fr), 2) frP - round(as.numeric(frP), 2) fac - round(as.numeric(fac), 2) facP - round(as.numeric(facP),2) res - data.frame(fi, fr, frP, fac, facP)# Make final table names(res) - c('Class limits', 'fi', 'fr', 'fr(%)', 'fac', 'fac(%)') return(res) } # # Common function # tb.make.table.II - function (x, k, breaks=c('Sturges', 'Scott', 'FD'), right=FALSE) { x - na.omit(x) # User defines only x and/or 'breaks' # (x, {k,}[breaks, right]) if (missing(k)) { brk - match.arg(breaks) switch(brk, Sturges = k - nclass.Sturges(x), Scott = k - nclass.scott(x), FD = k - nclass.FD(x)) tmp - range(x) start - tmp[1] - abs(tmp[2])/100 end - tmp[2] + abs(tmp[2])/100 R - end-start h - R/k } # User defines 'x' and 'k' # (x, k,[breaks, right]) else { tmp - range(x) start - tmp[1] - abs(tmp[2])/100 end - tmp[2] + abs(tmp[2])/100 R - end-start h - R/abs(k) } tbl - tb.make.table.I(x, start, end, h, right) return(tbl) } # # With Gabor Grotendieck suggestions (thanks Gabor, very much!) # tb.table - function(x, ...) UseMethod(tb.table) # # Table form vectors # tb.table.default - function(x, k, start, end, h, breaks=c('Sturges', 'Scott', 'FD'), right=FALSE) { # User defines nothing or not 'x' isn't numeric - stop stopifnot(is.numeric(x)) x - na.omit(x) # User defines only 'x' # (x, {k, start, end, h}, [breaks, right]) if (missing(k) missing(start) missing(end) missing(h) ) { brk - match.arg(breaks) switch(brk, Sturges = k - nclass.Sturges(x), Scott = k - nclass.scott(x), FD = k - nclass.FD(x)) tmp - range(x) start - tmp[1] - abs(tmp[2])/100 end - tmp[2] + abs(tmp[2])/100 R - end-start h - R/k } # User defines 'x' and 'k' # (x, k, {start, end, h}, [breaks, right]) else if (missing(start) missing(end) missing(h)) { stopifnot(length(k) = 1) tmp - range(x) start - tmp[1] - abs(tmp[2])/100 end - tmp[2] + abs(tmp[2])/100 R - end-start h - R/abs(k) } # User defines 'x', 'start' and 'end' # (x, {k,} start, end, {h,} [breaks, right]) else if (missing(k) missing(h)) { stopifnot(length(start) = 1, length(end) =1) tmp - range(x) R - end-start k - sqrt(abs(R)) if (k 5) k - 5 # min value of k h - R/k } # User defines 'x', 'start', 'end' and 'h' # (x, {k,} start, end, h, [breaks, right]) else if (missing(k)) { stopifnot(length(start) = 1, length(end) = 1, length(h) = 1) } else stop('Error, please, see the function sintax!') tbl - tb.make.table.I(x, start, end, h, right) return(tbl) } # # Table form data.frame # tb.table.data.frame - function(df, k, by, breaks=c('Sturges', 'Scott', 'FD'), right=FALSE) { stopifnot(is.data.frame(df)) tmpList - list() nameF - character() nameY - character() # User didn't defines a factor if (missing(by)) { logCol - sapply(df, is.numeric) for (i in 1:ncol(df)) { if (logCol[i]) { x - as.matrix(df[ ,i]) tbl - tb.make.table.II(x, k,