Post

Created by @johnd123
 at October 19th 2023, 7:23:48 pm.

R Syntax

R is a powerful programming language commonly used for statistical computing and graphics. Understanding the basic syntax is essential for writing and executing R code. Let's dive into the fundamental elements:

  • Comments: You can add comments in R using the '#' symbol. For example, '# This is a comment'.
  • Assignments: To assign a value to a variable, use the assignment operator '<-', or the equals sign '='. For example, 'x <- 5' or 'y = 10'.

Data Types

R supports various data types that are crucial for working with data. Here are some common ones:

  • Numeric: Used to represent numeric values, such as 3.14 or 100.25.
  • Character: Used to store text or strings, enclosed in either single or double quotes. For example, 'hello' or "world".
  • Logical: Represents true/false values. R has two special keywords, 'TRUE' and 'FALSE', for logical values.

Variables

Variables in R are containers used to store data. Here's how you can define variables:

# Assigning a numeric value to a variable
radius <- 5

# Assigning a character value to a variable
name <- 'John'

# Assigning a logical value to a variable
isStudent <- TRUE

By understanding R's syntax and data types, you are now equipped to write basic R code and work with different types of data effectively.

Keep practicing and exploring R's vast capabilities! You'll soon become a master of data analysis!