Nizamuddin Siddiqui has Published 2307 Articles

Select columns of an R data frame and skip if does not exist.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 14:02:39

567 Views

Sometimes we have a large number of columns in the data frame and we know the name of some columns but among known ones some does not exist in the data frame. Now if we want to select the columns that we know and skip the ones that do not ... Read More

How to divide columns of a matrix by vector elements in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 13:49:11

2K+ Views

Suppose we have a vector say V that contains five elements and a matrix say M that has five columns. Now again, suppose that we want to divide each column in M by corresponding value in vector V, which means first column in M will be divided by first value ... Read More

How to create a time series plot in R without time vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 10:03:49

327 Views

To create a time series plot in R without time vector, we can use ts.plot function.For Example, if we have a vector called X then we can create the time series plot of X by using the command ts.plot(X), the Output of this command will have a time axis in ... Read More

How to create vertical line in xyplot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 09:37:20

332 Views

To create vertical line in xyplot, we can use abline function.For Example, if we have a data frame called df that contains two columns say X and Y and we want to create a scatterplot between X and Y using xyplot with a vertical line at X = 2 then ... Read More

Combine values of two columns separated with hyphen in an R data frame.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 09:29:59

733 Views

To combine values of two columns separated with hyphen in an R data frame, we can use apply function.For Example, if we have a data frame called df that contains only two columns say X and Y then we can combine the values in X and Y by using the ... Read More

How to find the class of columns of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 08:48:14

5K+ Views

To find the class of columns of an R data frame, we can use class function along with sapply and as.data.frame function.For Example, if we have a data frame called DF then we can find the class of columns in DF by using the command as follows −data.frame(sapply(DF, class))Example 1Consider ... Read More

How to check which list element contains a particular value in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 08:16:42

992 Views

A list in R can have large number of elements and also of different types. If we have a list that contain vectors and we want to check which list element contains a particular value then we can use which function along with sapply function.For Example, if we have a ... Read More

How to convert strings in R data frame to unique integers?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 07:55:11

1K+ Views

To convert strings in R data frame to unique integers, we first need to extract the unique strings in the data frame and then read them inside data.frame function with as.numeric along with factor function.Check out the below Examples to understand how it works.Example 1Consider the below data frame −x1Read More

Create a date column in R using a date vector excluding weekends.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 07:33:11

2K+ Views

If we have a vector of dates that contains all days in a week then we can use that vector to create a date column by excluding weekends with the help of subsetting the vector as shown in the below Examples. After subsetting the vector, we will just need to ... Read More

How to change the border line type in base R boxplot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 28-Oct-2021 07:23:02

626 Views

The default boxplot in R has straight border line type that display end point(s) excluding outliers. To change these border lines from a boxplot, we can use staplelty argument.For Example, if we have a vector called X then we can create the boxplot of X with different border line type ... Read More

Advertisements