How do I introduce a tilde (~) in R?
2 answers
(tilde <- rawToChar(as.raw(126)))
# [1] "~"
You can use this variable when you need a tilde in text.
summary(lm(paste0("Sepal.Length", tilde, "Sepal.Width"), data=iris))
# Call:
# lm(formula = paste0("Sepal.Length", tilde, "Sepal.Width"), data = iris)
#
# Residuals:
# Min 1Q Median 3Q Max
# -1.5561 -0.6333 -0.1120 0.5579 2.2226
#
# Coefficients:
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 6.5262 0.4789 13.63 <2e-16 ***
# Sepal.Width -0.2234 0.1551 -1.44 0.152
# ---
# Signif. codes: 0 β***β 0.001 β**β 0.01 β*β 0.05 β.β 0.1 β β 1
#
# Residual standard error: 0.8251 on 148 degrees of freedom
# Multiple R-squared: 0.01382, Adjusted R-squared: 0.007159
# F-statistic: 2.074 on 1 and 148 DF, p-value: 0.1519
Alternatively, you can just type tilde
and copy and paste the character.
+6
source to share