Nizamuddin Siddiqui has Published 2307 Articles

How to find the total by year column in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:41:23

1K+ Views

To find the total by year column in an R data frame, we can use aggregate function with sum function.For Example, if we have a data frame called df that contains a year colmn say Year and a numerical column say Demand then we can find the total Demand by ... Read More

How to standardize selected columns in data.table object in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:36:05

189 Views

To standardize selected columns in data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use scale function and cbind function with subsetting to standardize selected columns.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) var1Read More

How to save a matrix as CSV file using R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:35:08

8K+ Views

To save a matrix as CSV file using R, we can use write.matrix function of MASS package. For Example, if we have a matrix called M and we want to save it as CSV file then we can use the below mentioned command −write.matrix(M, file="Mat.csv")ExampleFollowing snippet creates a sample matrix ... Read More

How to repeat column values in R matrix by values in another column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:29:30

378 Views

To repeat column values in R matrix by values in another column, we can follow the below steps −First of all, create a matrix.Then, use rep function along with cbind function to repeat column values in the matrix by values in another column.ExampleCreate the matrixLet’s create a matrix as shown ... Read More

How to remove multiple columns from matrix in R by using their names?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:24:26

337 Views

To remove multiple columns from matrix in R by using their names, we can follow the below steps −First of all, create a matrix.Then, add names to columns of the matrix.After that, subset the matrix by deselecting the desired columns with negation and single square brackets for subsetting.ExampleCreate the matrixLet’s ... Read More

Combine two columns by ignoring missing values if exists in one column in R data frame.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:17:34

3K+ Views

To combine two columns by ignoring missing values if exists in one column in R data frame, we can use paste function and is.na function.For Example, if we have a data frame called df that contains two columns say C1 and C2 where C2 contains some missing values then we ... Read More

How to find the index of values in matrix column in R if they occur once?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:17:00

252 Views

To find the index of values in R matrix column if they occur once, we can follow the below steps −First of all, create a matrix.Then, use which function along with duplicated function and single square brackets for subsetting to find the index of values in a column if they ... Read More

How to subset an R data frame by specifying columns that contains NA?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:14:09

297 Views

To subset an R data frame by specifying columns that contains NA, we can follow the below steps −First of all, create a data frame with some columns containing NAs.Then, use is.na along with subset function to subset the data frame by specifying columns that contains NA.ExampleCreate the data frameLet’s ... Read More

Find the common elements between two columns of an R dataframe.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:10:25

5K+ Views

To find the common elements between two columns of an R data frame, we can use intersect function.For Example, if we have a data frame called df that contains two columns say X and Y then we can find the common elements between X and Y by using the below ... Read More

Find the number of non-missing values in each group of an R data frame.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Nov-2021 10:04:49

174 Views

To find the number of non-missing values in each group of an R data frame, we can convert the data frame to data.table object and then use the sum function with negation of is.na.For Example, if we have a data frame called df that contains a grouping column say Group ... Read More

Advertisements