DAR LEbhsuussbjshsbshshsbsbbbsbsCTURE 3.pptx

collegework11 9 views 16 slides Sep 10, 2024
Slide 1
Slide 1 of 16
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16

About This Presentation

Bzbsbshshshs


Slide Content

Basics of R Compiled and Presented by: Dr. Chetna Arora

Commands What: Instructions you give to R to perform a task. Example: print("Hello, World!") Explanation: This command tells R to display the text "Hello, World!" on the screen

Variables What: Named storage for values that you can use later. Example: x <- 5 Explanation: The variable x now stores the value 5. You can use x in calculations or other commands.

Syntax What: The set of rules that define how to write commands in R. Example: y <- x + 3 Explanation: This follows R's syntax rules to create a variable y that stores the value of x plus 3.

Functions What: Predefined or user-defined actions that perform specific tasks. Example: sum(1, 2, 3) Explanation: The sum function adds the numbers 1, 2, and 3 together, returning 6.

Loops What: A way to repeat a set of commands multiple times. Types: repeat,while,for

Vectors What: A sequence of data elements of the same type. Example: numbers <- c(1, 2, 3, 4, 5) Explanation: This creates a vector named numbers that contains the numbers 1 through 5. A vector is the basic data structure in R that stores data of similar types Example: Suppose we need to record the age of 5 employees. Instead of creating 5 separate variables, we can simply create a vector.

Data Types What: The type of data stored in a variable, such as numbers, text, etc.

Strings What: A sequence of characters, often used for text. Example: greeting <- "Good Morning!“ Explanation: The variable greeting contains the string "Good Morning

Assignment Operator What: Used to assign values to variables. Example: x <- 10 Explanation: The <- symbol assigns the value 10 to the variable x. You can also use = like x = 10

Arithmetic Operations What: Basic math operations you can perform in R. Example: addition <- 5 + 3 subtraction <- 10 – 4 multiplication <- 2 * 6division <- 15 / 3 Explanation: These operations are straightforward: + for addition, - for subtraction, * for multiplication, and / for division.1 Logical Operators What: Used to perform comparisons and return TRUE or FALSE.

Conditional Statements What: Allow your code to make decisions based on conditions. Example: x <- 10if (x > 5) { print("x is greater than 5")} else { print("x is 5 or less")} Explanation: This code checks if x is greater than 5 and prints a message accordingly

Data Frames What: A table-like structure to store data in rows and columns. Example : df <- data.frame (Name = c("Alice", "Bob"), Age = c(25, 30)) Explanation : This creates a data frame with two columns (Name and Age) and two rows. Lists What: A collection of elements that can be of different types. Example : my_list <- list(name = "John", age = 30, scores = c(85, 90, 88)) Explanation: my_list is a list containing a string (name), a number (age), and a vector (scores).

Factors What: Used for categorical data, like gender or types of items. Example: gender <- factor(c("male", "female", "female", "male")) Explanation: The gender variable stores the categories "male" and "female".

Packages What: Collections of R functions, data, and compiled code that extend R's capabilities. Example : install.packages ("ggplot2")library(ggplot2) Explanation: install.packages downloads a package, and library loads it for use

Reading and Writing Data What: Loading data from files and saving data to files. Example: data <- read.csv("data.csv") write.csv(data, "output.csv") Explanation: read.csv loads data from a CSV file, and write.csv saves data to a CSV file. Plotting What: Creating visualizations of your data. Example : plot( cars$speed , cars$dist ) Explanation : This creates a basic scatter plot of the cars dataset, plotting speed against dist. R Markdown What: A file format for creating dynamic documents with R. Example: itle : "R Markdown Example"output : html_document ---```{r}summary(cars) Explanation: R Markdown allows you to combine text, code, and output in a single document, making it great for reports.