library(ards)
library(dplyr)
# Initialize the ARDS
# - These values will be common through the dataset
init_ards(studyid = "IRIS",
tableid = "01", adsns = "iris",
population = "all flowers",
time = "1973")
# Perform analysis on Petal.Length
# - Using Species as a by-group
analdf1 <- iris |>
select(Petal.Length, Species) |>
group_by(Species) |>
summarize(n = n(),
mean = mean(Petal.Length),
std = sd(Petal.Length),
min = min(Petal.Length),
max = max(Petal.Length)) |>
add_ards(statvars = c("n", "mean", "std", "min", "max"),
statdesc = c("Count", "Mean", "STD", "Minimum", "Maximum"),
anal_var = "Petal.Length", trtvar = "Species")
# Perform analysis on Petal.Width
# - Using Species as a by-group
analdf2 <- iris |>
select(Petal.Width, Species) |>
group_by(Species) |>
summarize(n = n(),
mean = mean(Petal.Width),
std = sd(Petal.Width),
min = min(Petal.Width),
max = max(Petal.Width)) |>
add_ards(statvars = c("n", "mean", "std", "min", "max"),
statdesc = c("Count", "Mean", "STD", "Minimum", "Maximum"),
anal_var = "Petal.Width", trtvar = "Species")
# Get the ARDS
ards <- get_ards()
# Convert back to wide format
res <- restore_ards(ards)
# View list names
print(names(res))
# [1] "Petal.Length" "Petal.Width"
# Pull out Petal.Length
r1 <- res$Petal.Length
# View column names on Petal.Length
print(names(r1))
# [1] "Species" "anal_var" "n" "mean" "std" "min" "max"
# View stat data on Petal.Length
print(r1)
# Species anal_var n mean std min max
# 1 setosa Petal.Length 50 1.462 0.1736640 1.0 1.9
# 2 versicolor Petal.Length 50 4.260 0.4699110 3.0 5.1
# 3 virginica Petal.Length 50 5.552 0.5518947 4.5 6.9
# Uncomment to view restored datasets
# View(res$Petal.Length)
# View(res$Petal.Width)
Run the code above in your browser using DataLab