Data Types and Variables
In R programming, a user can create vectors, matrices, even arrays and data frames to enable him or her to store data. Follow the below example on how to create a vector and a data frame:
# Create a vector
oceans <- c(“Arctic”, “Atlantic”, “Indian”, “Pacific”, “Southern”)
avg_depth <- c(1.2, 3.65, 3.74, 3.97, 3.27)
# Create a data frame
oceans_depth <- data.frame(oceans, avg_depth)
print(oceans_depth)
Data Import and Export
Precisely, a user can import and export his or her data at the same time without having issues or difficulties. This, however can be donw through or by using the data import and export using the various functions in R. Consider the below using the import, thus a CSV file:
# Import a CSV file
world_population <- read.csv(“world_population.csv”)
Data Visualization
A user can also create lots of visualized files such as types in plots in the R programming language. Follow the below example on creating a scatter plot in R programming;very interesting though:
# Create a scatter plot
plot(world_population$Population, world_population$GDP, main=”Scatter Plot”, xlab=”Population”, ylab=”GDP”)
Control Structures
Another very good basic command is by using the Control Structures, with the control structures, a user can use such as the if-else statements and loops in the R programming language or environment.
Take a good look:
# If-else statement
x <- 10
if (x > 5) {
print(“x is greater than 5”)
} else {
print(“x is less than or equal to 5”)
}
Function Command
Next is the Function command or syntax, with regard to the name command, its practical features helps users to create their own functions and that is the most advantage and first class command in R programming.
Taake the example below when a user want to create his or her own function:
# Create a function
square <- function(x) {
return(x^2)
}
print(square(5))
Packages
Also, we have another feature, that is working with Packages in R programming. Packages in R programming can be used to extend most functionalities. Below is an example of installing and loading a package(s) in R programming.
# Install a package
install.packages(“ggplot2”)
# Load a package
library(ggplot2)
There are lots of the basic practical topics, however, reach out through 0553230862(WhatsApp) in case you need more and private lessons.
About Author
Discover more from SURFCLOUD TECHNOLOGY
Subscribe to get the latest posts sent to your email.