Basic Practical Topics For Every Beginner Explained In R Programming

Data Types and Variables

In R programming, a user can create vectors, matrices, even arrays and data frames to enable him or her 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 done 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; it’s 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 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

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 advantageous and first class command in R programming.

Take 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)

 

About Author


Discover more from SURFCLOUD TECHNOLOGY

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from SURFCLOUD TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading