Found 2038 Articles for R Programming

Joining Data in R with data.table

Bhuwanesh Nainwal
Updated on 17-Jan-2023 15:06:04

1K+ Views

In this article, we will discuss joining data in R using data.table package. By the term “joining data” we mean to say that performing different types of joins operations like INNER JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, AND FULL OUTER JOIN between two or more tables. The main purpose of doing join operations between tables is to access data from multiple tables on the basis of some attribute (or column) condition. R provides us data.table package with the help of which we can handle tabular data (having rows and columns) very efficiently. This package was launched as an alternative ... Read More

Functional Programming with purrr

Bhuwanesh Nainwal
Updated on 17-Jan-2023 16:18:23

200 Views

Functional programming is a programming methodology in which we construct programs by constructing and applying functions. More specifically in programs, we apply sequential pure functions rather than statements. A pure function is a function that accepts an input and produces a consistent value as an output. Also, during this process no augment or input stream is modified. Such functions are capable of doing a single operation but for carrying out complex operations we can combine them into sequences. In this tutorial, we will discuss functional programming using purr. Nowadays, Functional programming is important to master due to its capability to ... Read More

Defensive R Programming

Bhuwanesh Nainwal
Updated on 17-Jan-2023 14:54:01

276 Views

Defensive programming is a software development practice that involves designing and implementing code in a way that anticipates and prevents errors and vulnerabilities. In R programming, defensive programming involves using techniques and strategies to ensure that your R code is robust, reliable, and secure. By the word “Defensive” in defensive programming, most of you might be confused about whether it means writing such a code that doesn’t fail at all. But the actual definition of “Defensive programming” is writing such a code that fails properly. By “failing properly”, we mean − If the code fails, then it should be ... Read More

Dealing with Missing Data in R

Bhuwanesh Nainwal
Updated on 17-Jan-2023 16:12:22

23K+ Views

In data science, one of the common tasks is dealing with missing data. If we have missing data in your dataset, there are several ways to handle it in R programming. One way is to simply remove any rows or columns that contain missing data. Another way to handle missing data is to impute the missing values using a statistical method. This means replacing the missing values with estimates based on the other values in the dataset. For example, we can replace missing values with the mean or median value of the variable in which the missing values are found. ... Read More

Data Manipulation in R with data.table

Bhuwanesh Nainwal
Updated on 17-Jan-2023 14:17:38

1K+ Views

Data manipulation is a crucial step in the data analysis process, as it allows us to prepare and organize our data in a way that is suitable for the specific analysis or visualization. There are many different tools and techniques for data manipulation, depending on the type and structure of the data, as well as the specific goals of the manipulation. The data.table package is an R package that provides an enhanced version of the data.frame class in R. It’s syntax and features make it easier and faster to manipulate and work with large datasets. The date.table is one ... Read More

How to find the moving standard deviation in an R matrix?

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:52:55

277 Views

To find the moving standard deviation in a matrix is done in the same way as in a data frame, we just need to use the matrix object name in place of data frame name. Hence, we can make use of rollapply function of zoo package for this purpose.For example, if we have a matrix called M and we want to find the 2 moving standard deviations then we can use the below given command −rollapply(M,width=2,FUN=sd,fill=0,align="r")Example 1Following snippet creates a matrix −M1

How to round the summary output in R?

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:49:16

3K+ Views

To round the output of summary function in R, we can use digits argument while applying the summary function.For example, if we have a data frame called df then to find the summary statistics with two digits in the output we can use the below given command −summary(df, digits=2)Example 1Following snippet creates a dataframe −head(iris, 20) The following dataframe is created − Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1    5.1       3.5         1.4         0.2         setosa 2    4.9       3.0         1.4 ... Read More

How to find the row wise sum for n number of columns in R?

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:36:30

3K+ Views

To find the row wise sum of n number of columns can be found by using the rowSums function along with subsetting of the columns with single square brackets.For example, if we have a data frame called df that contains five columns and we want to find the row sums for last three columns then we can use the following command −df$Sum_3

How to extract the maximum value from named vector in R?

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:31:08

753 Views

To extract the maximum value from named vector in R, we can use which.max function.For example, if we have a vector called X which is a named vector then we can use the following command to find the maximum value in X.X[which.max(X)]Check out the below examples to understand how it works.Example 1Following snippet creates a vector −x1

How to reduce the space between Y-axis value and ticks using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:21:07

4K+ Views

To reduce the space between axis value and ticks using ggplot2, we can use theme function of ggplot2 package with margin set to 0.For example, if we have a data frame called df that contains two columns say x and y then the scatterplot between x and y with reduced space between Y-axis value and ticks can be created by using the following command −ggplot(df,aes(x,y))+geom_point()+theme(axis.text.y=element_text(margin=margin(r=0)))ExampleFollowing snippet creates a sample data frame −x

Advertisements