numbers <- c(1, 2, 3, 4, 5) # Numeric vector
names <- c("Asha", "Raj", "Zara") # Character vector
names
[1] "Asha" "Raj" "Zara"
Dr. Ajay Kumar Koli, PhD | SARA Institute of Data Science, India
In R, everything you create or work with is stored as an object.
Objects can be numbers, text, data tables, functions, or even plots.
Think of an object as a named container that stores information in your R environment.
numbers <- c(1, 2, 3, 4, 5) # Numeric vector
names <- c("Asha", "Raj", "Zara") # Character vector
names
[1] "Asha" "Raj" "Zara"
Curious Candy 🍬🍭🍬
Why are we not seeing numbers in the results?
List – collection of different types of objects
A name cannot start with a number.
A name cannot use some special symbols, like ^
, !
, $
, @
, +
, -
, /
, or *
,:
.
Avoid caps.
Avoid space.
Use dash (like weight-kg) or underscore (like weight_kg).
If chronology matters then add date (2020-09-05-file-name).
Important
R assignment operators: Assignment operators are used to assign values to variables.
object_name <- c(2, 3, 4, 5)
object_name
Type | Description | Example |
---|---|---|
numeric |
Numbers (floating point) | 3.14 , 2 , -5 |
integer |
Whole numbers | 2L , 100L |
character |
Text strings | "R is great" |
logical |
Boolean values | TRUE , FALSE |
👇 Something Like This 😻😻
name income age place weight_kg
1 Bhim 23000 23 MH 50
2 Rama 25000 25 RJ 52
3 Sara 16000 16 DL 61
4 Phule 4000 40 HR 40
5 Savitri 34000 34 HR 70
csv
fileWriting comments in R code (or any programming language) is essential for making your code understandable, maintainable, and collaborative.
Comments are lines in the code that are not executed; they’re used to explain what the code does, why certain decisions were made, and how to use or modify the code.
Use #
to begin a comment.
R ignores everything after the #
on that line.
🛑 Bad Practice: No Comments
🙁 This code works, but it’s not clear what it’s doing or why.
>
in console type
?your query
for example ?knitr
.
for example ?mtcars
.
for example ?dplyr
.
Social media #RStats