Basics of R Programming_Ghosh - Tagged
Basics of R Programming_Ghosh - Tagged
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