Dapply: Apply Functions Over Data Frames

View source: R/pivot-dapply.R

DapplyR Documentation

Apply Functions Over Data Frames

Description

Dapply, dapply2: plyr::llply() + Label()

dapply2: Copie of plyr::llply()

Scaling and Centering of data.frame

transpose2: Data Frame Transpose

Alternative: data.table::transpose(l, make.names = 1, keep.names = "Item")

transpose_factor: Rangreihe transortieren

Usage

Dapply(x, ...)

## S3 method for class 'formula'
Dapply(x, data, fun = function(y) as.numeric(y), stringsAsFactors = FALSE, ...)

## S3 method for class 'data.frame'
Dapply(x, ..., fun = function(y) as.numeric(y), stringsAsFactors = FALSE)

dapply2(x, fun = function(x) as.numeric(x), stringsAsFactors = FALSE, ...)

scale_by(x, ..., by = NULL, scale = 0.5, reference = 1, digits = 3)

transpose2(x, ...)

## Default S3 method:
transpose2(x, ...)

## S3 method for class 'tbl_df'
transpose2(x, ...)

## S3 method for class 'data.frame'
transpose2(x, ...)

transpose_factor(x, levels = names(x))

Arguments

x

data.frame

...

key="Item"

data

Data.frame

fun

funktion function(x) as.numeric(x)

stringsAsFactors

logical: should character vectors be converted to factors?

by

data.frame, measure and by

scale

default = 1/2 (aproximativ range between -1 and +1)

reference

for factor which level devault = 1

digits

digits

levels

optional Levels

Value

data.frame

same as x

gleiches Objekt

data.frame

Examples

 
df1 <- Label(data.frame(
  month = rep(1:3, 2),
  student = rep(c("Amy", "Bob"), each = 3),
  A = c(9, 7, 6, 8, 6, 9),
  B = c(6, 7, 8, 5, 6, 7)
),
A = "Deutsch",
B = "Mathe")

rs1 <- Dapply(~ A + B,
              df1,
              cut,
              breaks = 3,
              labels = c(1:3))
              

#' set.seed(1)
dat <- data.frame(
  x = round(c(rnorm(5), rnorm(5, 10, 2)), 1),
  y = c(12, 13, 10, 14, 10, 26, 25, 31, 28, 20) ,
  g =  factor(c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE), c(TRUE, FALSE))
)


dat |>
  scale_by(x, by = ~ g, scale = 1)  #|>  Tbll_desc(x, y, by =  ~ g)


transpose2(data.frame(pos = c("A", "B"), x = 1:2))

transpose2(data.frame(
  pos = c("A", "B" , "C"),
  x = 1:3,
  y = 3:5
))

   dat <-   data.frame(
  hoch = factor(c("A", "A", "A", "C", "C", "A"),   c("A", "B", "C", "D")),
  mittel = factor(c("B", "B", "B", "A", "B", "D"),   c("A", "B", "C", "D")),
  gering = factor(c("C", "C", "C", "B", "A", "B"),   c("A", "B", "C", "D"))
  )
  transpose_factor(dat, NULL)
  transpose_factor(dat)
#'

   dat <-   data.frame(
  hoch = factor(c("A", "A", "A", "C", "C", "A"),   c("A", "B", "C", "D")),
  mittel = factor(c("B", "B", "B", "A", "B", "D"),   c("A", "B", "C", "D")),
  gering = factor(c("C", "C", "C", "B", "A", "B"),   c("A", "B", "C", "D"))
  )
  transpose_factor(dat, NULL)
  transpose_factor(dat)

stp4/stp25tools documentation built on Feb. 27, 2025, 11:14 p.m.