Nizamuddin Siddiqui has Published 2307 Articles

How to find the sum of two list elements in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Nov-2020 05:08:16

512 Views

The list elements of two lists cannot be added directly but we can do this addition by unlisting the elements. To do this, we would need to use lapply function. For example, if we have two lists defined as x and y then the sum of the elements in these ... Read More

How to create a data frame in R with list elements?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Nov-2020 05:06:42

503 Views

If a list has the same length of elements (not sub-elements) as the length of each vector for which we want to create the data frame then we first need to create the data frame of vectors then we can easily add the list into the data frame. But if ... Read More

How to create a horizontal line in a histogram in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Nov-2020 05:02:39

1K+ Views

A horizontal line in a histogram is not much useful but we might want to create it in some situations such as where we want to display a specific value on the Y-axis that helps us to differentiate in the density of frequencies above or below a certain value. To ... Read More

How to display the superscript for a single variable in a base R plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Nov-2020 05:00:09

122 Views

To display the superscript in a base R plot, we would need to use expression function inside text function. For example, if we want to display X-square inside a blank plot in base R then we can use the below code:plot(1:10, type="n") text(2, 2, expression(X^2))Example1> plot(1:10, type="n") > text(2, 2, ... Read More

How to extract columns based on particular column values of an R data frame that matcha pattern?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Nov-2020 04:58:32

365 Views

The column values of an R data frame can be easily extracted by subsetting with single square brackets but if we want to extract the column values that match a pattern then we need to use grepl function inside single square brackets, this will help us to match the pattern ... Read More

How to create a sphere in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Nov-2020 04:52:10

441 Views

To create a sphere, we can use spheres3d function of rgl package. The rgl package is specifically designed to create real-time interactive 3D plots. If we want to create a sphere then we need to pass the values for the three axes and the radius of the sphere. We can ... Read More

How to replace missing values in a column with corresponding values in other column of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Nov-2020 08:23:52

359 Views

Often, we get missing data for analysis and we need to replace those missing values with something. Sometimes, we might want to replace them with the corresponding values in other column especially in situations when both the columns depict similar characteristics. This type of replacement can be easily done with ... Read More

How to create a matrix using vector generated with rep function in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Nov-2020 08:21:56

271 Views

Matrix can be only generated if we pass an even number of elements for it. If we want to create a matrix using vector generated with rep function then the length of this vector must be divisible by 2. For example, if we have a vector x that is created ... Read More

How to name a data frame column with a vector value that has the same name in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Nov-2020 08:19:03

443 Views

To change the column name of a data frame in R, we can use setNames function. For example, if we have a data frame called df that contains column x and we want to change it to value “Ratings” which is stored in a vector called x then we can ... Read More

How to get the list of packages installed in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Nov-2020 08:16:59

465 Views

There is no limitation to installation of packages in R but base R also has some packages associated to it. Hence, there is no need to install or load them in R console every time. We can directly use any of the base R package functions to perform the analysis. ... Read More

Advertisements