-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 020990e
Showing
5 changed files
with
82 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,15 @@ | ||
Package: tabmofo | ||
Type: Package | ||
Title: My tabmofo | ||
Version: 1.0.0 | ||
Date: 2024-03-07 | ||
Author: [yuanttx] | ||
Maintainer: yuanttx <[email protected]> | ||
Description: Some functions for processing tables. | ||
License: GPL-3 | ||
Depends: R (>= 3.6.0) | ||
Imports: | ||
Suggests: | ||
VignetteBuilder: knitr | ||
NeedsCompilation: no | ||
Packaged: 2024-03-07 07:40:07 UTC; yuanhj |
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,2 @@ | ||
|
||
export(varsVenn, char2numf, NA2Numf) |
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,55 @@ | ||
#' varsVenn | ||
#' | ||
#' This is varsVenn. | ||
#' | ||
#' @param indat A list of sets | ||
#' @return A table | ||
varsVenn <- function(indat) { | ||
SamNum <- length(indat) | ||
SamNM <- names(indat) | ||
inall <- c() | ||
for (i in seq_len(SamNum)) { | ||
assign(paste0("len", i), indat[[i]]) | ||
inall <- unique(c(inall, get(paste0("len", i)))) | ||
} | ||
medat <- data.frame(.allvars = inall) | ||
rownames(medat) <- medat$.allvars | ||
for (k in seq_len(SamNum)) { | ||
checkVars <- get(paste0("len", k)) | ||
medat <- within(medat, { | ||
tempname <- ifelse(inall %in% checkVars, 1, 0) # nolint | ||
}) | ||
names(medat)[k + 1] <- SamNM[k] | ||
} | ||
medat <- medat[, -1] | ||
medat <- cbind(medat, RowSum = rowSums(medat)) | ||
return(medat) | ||
} | ||
|
||
|
||
#' char2numf | ||
#' | ||
#' This is char2numf. charatrs to numbers | ||
#' | ||
#' @param indat A list of sets | ||
#' @return A table | ||
char2numf <- function(indat) { | ||
NumDat <- indat | ||
NumDat <- apply(as.matrix(NumDat), 2, function(x) as.numeric(x)) | ||
NumDat <- as.data.frame(NumDat) | ||
return(NumDat) | ||
} | ||
|
||
|
||
#' replace the NA | ||
#' | ||
#' This is char2numf. charatrs to numbers | ||
#' | ||
#' @param indat A list of sets | ||
#' @return A table | ||
NA2Numf <- function(indat) { | ||
NADat <- as.data.frame(indat) | ||
NADat <- apply(NADat, 2, function(x) { | ||
x[is.na(x)] <- mean(x, na.rm = TRUE) | ||
}) | ||
} |
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,6 @@ | ||
library(testthat) | ||
library(tabmofo) | ||
|
||
test_that("myfunction works", { | ||
char2numf("1") == 1 | ||
}) |
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,4 @@ | ||
library(tabmofo) | ||
|
||
#' vignette | ||
char2numf("1") |