Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 168 of 196

How to delete different rows and columns of a matrix using a single line code in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 04-Sep-2020 1K+ Views

Deletion or addition of rows and columns in a matrix of any size is mostly done by using single square brackets and it is also the easiest way. To delete rows and columns, we just need to use the column index or row index and if we want to delete more than one of them then we can separate them by commas by inserting them inside c as c(-1, -2). If we want to delete more than one rows or columns in a sequence then a colon can be used. Examples > M M Output ...

Read More

How to extract the frequencies from a histogram in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 04-Sep-2020 359 Views

When we create a histogram and save it in an object name then we can extract the frequencies as count for the mid values or breaks by calling that object. We can consider that mid values or breaks obtained by the object are the actual value against which the frequencies are plotted on the histogram.Examples> x1 Histogram1 Histogram1Output$breaks [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 $counts [1] 45 82 150 156 172 142 113 62 43 20 9 5 1 $density [1] 0.045 0.082 0.150 0.156 0.172 0.142 0.113 0.062 0.043 0.020 ...

Read More

How to add a horizontal line to the plot created by ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 04-Sep-2020 365 Views

When we create a plot, it shows the values passed by the function for creating the plot but we might want to display some other values to provide some information through the plot and that information could be a threshold value as a horizontal line or we can also call it a cut off value. This can be done by using geom_hline function of ggplot2 package.ExampleConsider the below data frame −> x y df dfOutput      x       y 1 0.27810573 2.6545571 2 1.39185082 3.4845292 3 -0.19068920 1.7043852 4 1.00791317 1.4324814 5 -1.74964913 1.7996093 6 -0.13123079 2.5004350 ...

Read More

How to split a string vector that contain strings of equal sizes and have spaces between values then extract only few values in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 04-Sep-2020 226 Views

A string vector can contain any value including spaces. Sometimes a string vector is read with some spaces as well and we want to split the vector then extract few values. For example, if a string has “ABC 123” then we might want to extract the number 123 so that we can use it in analysis. If the string vector has strings of equal sizes then it can be easily done with the help of substr function.Examples> x1 x1 [1] "1 00" "1 01" "1 02" "1 03" "1 03" "1 04" > Numeric_Last_two_x1 Numeric_Last_two_x1 [1] "00" "01" "02" "03" ...

Read More

How to convert unit of measurements of a value or a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 04-Sep-2020 828 Views

There are many units of measurements for a single object or item. For example, weight can be measured in milligrams, grams, kilograms, tons, oz, lbs, etc. Now suppose we have two variables that belong to the same unit of measurement as weight of a coca cola cans and weight of apple juice, if the weights given for both of these variables have different units like one having grams and the other having oz then we might want to convert one of them. This will help us to compare both the variables easily without conflicting the scale of measurements. Therefore, we ...

Read More

How to sort a vector in increasing order that contains numbers and characters in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 04-Sep-2020 268 Views

A vector can contain numbers, characters or both. The sorting of vectors that contain only numbers or only characters is not very difficult but if a vector contains both of them then it is a little tedious task. In R, we can sort a vector that contains numbers as well as characters with the help of order function but before doing this sorting we must look at the vector very carefully to check if the characters are different for the elements of the vector or not, if they are different then we can’t do this sorting in the manner explained ...

Read More

How to create a row at the end an R data frame with column totals?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 04-Sep-2020 317 Views

In data analysis, we often need column totals, especially in situations where we want to perform the analysis in a step by step manner. There are many analytical techniques in which we find the column totals such as ANALYSIS OF VARIANCE, CORRELATION, REGRESSION, etc. To find the column totals, we can use colSums function and use the single square brackets to put these totals as a row in the data frame. Example1 Consider the below data frame − > x1 x2 x3 df1 df1 Output x1 x2 x3 1 1 1 1 2 2 2 2 3 3 3 ...

Read More

How to replace space in a string value for some elements in a column of an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 29-Aug-2020 508 Views

Most of the times, the string data is in bad shape and we need to make it appropriate so that we can easily proceed with the analysis. There is also a situation in which a string column has some values where an extra space is used which was not required, therefore, it does not match with the rest of the column values. To remove these spaces, we can use lapply and gsub function.ExampleConsider the below data frame −x1

Read More

How to change the column names in R within aggregate function?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 29-Aug-2020 596 Views

The column names in an R data frame are an important part of the data because by reading the column names any viewer is likely to understand the theoretical background behind it. If that name is not appropriate then we might want to change it. While using the aggregate function to calculate mean or any other statistical summary, it is possible to change that name with another name by defining the new name with list.ExampleConsider the below data frame −set.seed(1) x1

Read More

How to find the row and column number for the minimum and maximum values in an R matrix?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 28-Aug-2020 403 Views

A matrix can have one or more than one minimum and maximum values. Also, the size of the matrix can be just one column and multiple rows or thousands of columns and thousands of rows. The row number and column number for the minimum and maximum values in a matrix can be found by using the following syntax −For Maximumwhich(“Matrix_Name”==min(“Matrix_Name”),arr.ind=TRUE)For Minimum>which(“Matrix_Name”==max(“Matrix_Name”),arr.ind=TRUE)Example M1

Read More
Showing 1671–1680 of 1,958 articles
« Prev 1 166 167 168 169 170 196 Next »
Advertisements