- Example 4a: t-test - Aster R

Teradata Aster® R User GuideUpdate 3

Aster R
December 2017
Programming Reference
User Guide
This example applies the t-test to check for a significant difference in the value of 'Sepal.Length' between samples of the setosa and the versicolor species.
  1. Use the subset() function to select all rows that are of non-virginica species, and keep the 'Sepal.Length' and 'Species' columns.
    iris.subset <- subset(iris, Species != ‘virginica’, select = c(Sepal.Length, Species))
  2. Write the t-test example function.

    This function applies the R function t.test() and returns the resulting p-value. It uses the formula option of the t.test() function.

    t.test.example <- function(y){
      p_value <- t.test(y[,1]~y[,2])$p.value

    In this example, y[,1] is the Sepal.Length data and y[,2] is the vector indicating which class (setosa or versicolor) an observation belongs to.

  3. Run the t-test example function in R.
    r.result <- t.test.example(iris.subset)
    > r.result
    [1] 3.746743e-17
  4. Use the dataframe 'iris.subset' to create a virtual data frame.
    ta.dropTable("iris_subset", schemaName = "public")
    tadf.iris.subset <- as.ta.data.frame(iris.subset, table = "iris_subset", schemaName = "public", tableType = "dimension", row.names = TRUE)
  5. Use the Aster R function aa.apply() to apply the function created in Step 2 to the virtual dataframe.
    db.result <- aa.apply(tadf.iris.subset, MARGIN = c(), t.test.example)
    > db.result
    [1] 3.746743e-17

    The MARGIN argument is set to c(). This indicates that the function is applied to the entire table.

    For details about the arguments and options of the function aa.apply(), refer to the inline help.