Tilde Operator

Description

R has a special operator, ~ to declare relationships between variables for a formula object. It either denotes the relationship between a response and explanatory variable. For example, to show that height of a plant is determined by light level, soil quality and amount of water you would write something similar to this code: height ~ light + soil + water

The operator can also be used to denote distribution in groups. This use of the operator is commonly seen in commands such as oneway.test or confint where multiple sets of data are passed to a function. We'll demonstrate this use in the sage cell.

Sage Cell

This use of the operator tells R that each value in the data column in info is a part of either group 1 or group 2, depending on the group number in its row.

Code

info <- data.frame(data = c(2.1, 9.6, 2.9, 2.6, 6.8, 0.2, 4.6, 3.8, 4.7, 7.9, 8.9, 8.7, 1.1, 2.5, 3.5, 12.2, 5.2, 13.1, 12.9, 11.5),
group = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
ID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
myFormula <- data ~ group
print(info)
print(myFormula)
NULL

Options

none

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 16 Jul 2019 02:10

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License