We all know R and Python dominates the data science world, and still, there's huge debate either you should go with R or Python. so keeping it aside let's start with the basics of R
R is primarily used in its dedicated IDE called R studio, However, it's open-source and free to use still tech giants like Microsoft, IBM provides commercial support to R for their customers. with 9000+ inbuilt packages, R is easy and most widely used for statistical computation, Machine Learning, Data Analysis.
R is platform-independent AKA it works with Windows, Linux, MACOS without a hassle. R Studio server is also available which allows users to use it on a web browser.
Data Types in R
- Logical
- Numeric
- Integer
- Complex
- Character
- Raw data type
Logical data type
logical data type contains true and false values
var1 < - TRUE
var2 < - FALSE
print(typeof(var1)) #returns "logical"
print(typeof(var2)) #returns "logical"
Numerical data type
Numeric data type consists of all numbers whole numbers as well as fractions.
var3 < - 10
print(var3)
typeof(var3) #returns "numeric"
var4 < - 10.4
print(var4)
typeof(var4) #returns "numeric"
integer data type
in integer data type we provide L at the end of number as stated in an example where L stands for strong
data < - 10L
print(data)
typeof(data) #returns "integer"
Complex data type
A complex data type is referred to as real + imaginary number
data <- 3 + 6i
print(data)
typeof(data) #returns "complex"
Character (string) data type
Character is a combination of alphanumeric values in quotation
data <- "Bangalore"
print(data)
typeof(data) #returns "character"
Raw data type (less used in data science)
x <- "jsgfuyewygfiubb"
y <- charToRaw(x)
typeof(x) #returns "character"
typeof(y) #returns "raw"
If you are from a python background it will be easy to relate with R, the difference is just R considers all values in one umbrella as numeric (Whole and Fraction) while in python whole number is under integer and fraction is under a float.
Variables
A valid variable name in R can start with a name, letters, dot but not started by a number.
there are three ways we can assign value or data to a variable
Equal to operator
var1 = 23:30
print(var1)
cat("var1 is ",var1)
# leftword assignment
var2 < - c("learn","R")
print(var2)
# rightword assignment
c("learn","R") - > var3
print(var3)
usually, all programmers who write codes in R use leftward assignment not necessarily for any specific reason but it's easy to understand.
Difference between print and cat (Concatenate) function.
Unlike other programming languages, the print function of R is pretty limited so there is cat function that serves the purpose
var1 < - c(23,25,26,74,52,62)
print(var1) #returns 23,25,26,74,52,62
# but if you want to print anything other than the
#variable print function cant do that
#so in such case, you need to use the cat function
cat("var1 is ", var1) #returns var1 is 23 25 26 74 52 62
What is C in R Programming language ?
So if you are reading this closely you have observed "c" in some statements and probably you may be wondering why that damm "C" is sitting there. let me tell you his story,
that "C" stands for combine when you need to assign more than one element to the variable then you need to add "C" basically what it does is it combines all the values and shows them in a single line. R is more obsessed with vectors. In R, numbers are just vectors of length one.
you can try it for fun to write code without C R will not accept that input because R is just a bit different, that's what makes it interesting.
So that's it for now folks will be writing some good informative stuff on R here on, let's see where it goes, I hope you find it interesting and want some for content, a simple way can be you can subscribe to the newsletter so you will get some insightful post right into your inbox, till then have a great whatever you wish you want to be great!