0% found this document useful (0 votes)
6 views18 pages

Basics of R Programming_Ghosh - Tagged

The document provides an introduction to R, covering its purpose, environment setup, and interface overview. It details various data types in R, including vectors, matrices, lists, and data frames, along with their use cases. Additionally, it explains basic operations in R, such as arithmetic, relational, and logical operations, as well as the concepts of functions and arguments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views18 pages

Basics of R Programming_Ghosh - Tagged

The document provides an introduction to R, covering its purpose, environment setup, and interface overview. It details various data types in R, including vectors, matrices, lists, and data frames, along with their use cases. Additionally, it explains basic operations in R, such as arithmetic, relational, and logical operations, as well as the concepts of functions and arguments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

• Brief purpose of R.

• Setting up the R environment (installing R and


RStudio).

Intro to R • R interface overview (console, script, environment,


plots, etc. in RStudio).
In short:
• Console: Direct interaction
with R for immediate
execution of commands.
• Script: A place to write, save,
and run longer pieces of R
code.
• Environment: Displays all
current objects/variables in
your workspace.
• Plots: Showcases the graphical
outputs.
Data Types in R
Vectors, matrices, lists, data frames
Vectors
• What it is: A one-dimensional array that holds elements of the same type
(e.g., all numbers, all strings).
• Differences from Others:
• Simplest data structure in R.
• All elements must be of the same type.
• When to Use:
• When you have a simple list of values to store of the same type, like scores from a
test.
• For performing basic operations and functions across multiple values
simultaneously (like finding the mean of a set of numbers).
Matrices
• What it is: A two-dimensional array where all elements are of the same
type.
• Differences from Others:
• Like a table, but every entry has to be the same type.
• Offers matrix-specific operations, like matrix multiplication.
• When to Use:
• When you have data that fits a tabular format, but all elements are of the same
type.
• For linear algebra operations or when needing to apply an operation across rows
or columns.
Lists:
• What it is: An ordered collection that can hold elements of different
types.
• Differences from Others:
• Can hold heterogeneous data (e.g., numbers, strings, even other lists or
functions).
• More complex than vectors or matrices but provides greater flexibility.
• When to Use:
• When you need to group different types of data together, like a mixed bag of
items.
• To create more complex data structures, like nested lists.
Data Frames:
• What it is: A two-dimensional table where columns can have different types.
• Differences from Others:
• Most similar to matrices, but allows different types across columns.
• Most common structure for storing datasets in R, especially when reading from
external sources like CSV files.
• When to Use:
• When dealing with datasets where different columns/variables have different types,
such as a mix of numerical and categorical data.
• For most data analysis tasks in R, given its structure and compatibility with many R
functions/packages.
Summary

Use vectors for simple one-dimensional datasets of a single type.

Use matrices when you have two-dimensional numerical data that needs matrix
operations.

Use lists when you have to mix and match data types or create complex nested
structures.

Use data frames for most standard data analysis tasks, especially when working
with tabular data where columns might have different types.
Basic Operations in R
Arithmetic Operations
Relational Operations
Logical Operations
Arithmetic
• These are basic math operations you'd use to calculate
things.

Operations
Relational •Relational operations let you compare values.

Operations
•When you use them, you'll get back either TRUE (if
the statement is true) or FALSE (if it's not).
Logical
1. AND (&):

This operator checks if both the conditions on its sides are TRUE. It only returns TRUE if both
conditions are true; otherwise, it returns FALSE.

Operations 2. OR (|):

The OR operator checks if at least one of the conditions on its sides is TRUE. If one or both are
TRUE, it returns TRUE. If both are FALSE, it returns FALSE.

3. NOT (!):

The NOT operator inverts the logical value. If the condition is TRUE, it will return FALSE and
vice versa.
What is a
Function?
• Imagine you have a magical calculator that
not only does basic arithmetic but can also
perform specific tasks like finding averages,
making plots, or running specific statistical
tests. In R, this magical calculator is made
up of "functions."
In simple terms:
• A function is like a mini-program or a recipe
that takes certain ingredients (input data
and settings) and gives you a result or an
outcome.
What are
Arguments?
• Every function or recipe requires certain
ingredients to work. In R, these ingredients
are known as "arguments". They are the
specific pieces of information or settings
that a function needs to perform its task.
In simple terms:
• Arguments are the details or specifics you
provide to a function. Think of it like telling
your magical calculator exactly how you
want a task done.
Example 1
• Finding the Average (mean):

Function: mean()
Argument: The list of numbers you want to find the average of.
Example 2
• Creating a Histogram:

Function: hist()
Argument: The data you want to visualize.
Example 3
• Running a Basic Correlation Test:

Function: cor.test()
Arguments: Two sets of data you want to find the correlation
between.
Basics of R Data types in R

Summary

Basic operations: Arithmetic, Arguments and Functions


relational, and logical operations

You might also like