Programming Articles - Page 1136 of 3366

How to divide matrix rows by number of columns in R?

Nizamuddin Siddiqui
Updated on 14-Aug-2021 07:55:23

240 Views

To divide matrix rows by number of columns in R, we can follow the below steps −First of all, create a matrix.Then, use apply function to divide the matrix rows by number of columns.Create the matrixLet’s create a matrix as shown below − Live DemoM

How to find the count of duplicate rows if they are greater than n in R data frame?

Nizamuddin Siddiqui
Updated on 14-Aug-2021 07:51:33

477 Views

To find the count of duplicate rows if they are greater than n in R data frame, we can follow the below steps −First of all, create a data frame.Then, count the duplicate rows if they are greater than a certain number using group_by_all, count, and filter function of dplyr package.Create the data frameLet's create a data frame as shown below − Live Demox

How to randomize column values of a data.table object for a set of columns in R?

Nizamuddin Siddiqui
Updated on 07-Aug-2021 09:12:16

207 Views

To randomize column values of a data.table object for a set of columns in R, we can follow the below steps −First of all, create a data.table object.Then, use sample function for randomizationwith lapply while selecting the columns with SDcols.Create the data frameLet's create a data frame as shown below −Examplelibrary(data.table) ID

How to randomize column values of a data.table object for all columns in R?

Nizamuddin Siddiqui
Updated on 14-Aug-2021 07:47:14

268 Views

To randomize column values of a data.table object for all columns in R, we can follow the below steps −First of all, create a data.table object.Then, use sample function with lapply to randomize the columns of the data.table object.Create the data frameLet's create a data frame as shown below −library(data.table) x

How to create a clone of a data frame in R without data values?

Nizamuddin Siddiqui
Updated on 14-Aug-2021 07:44:35

694 Views

To create a clone of a data frame in R without data values, we can follow the below steps −First of all, create a data frame.Then, create the clone of the data frame by subsetting zero rows.Example 1Create the data frameLet's create a data frame as shown below − Live Demox1

How to filter data frame by categorical variable in R?

Nizamuddin Siddiqui
Updated on 14-Aug-2021 07:42:03

4K+ Views

To filter data frame by categorical variable in R, we can follow the below steps −Use inbuilt data sets or create a new data set and look at top few rows in the data set.Then, look at the bottom few rows in the data set.Check the data structure.Filter the data by categorical column using split function.Use inbuilt data setLet’s consider CO2 data set in base R − Live Demodata(CO2) head(CO2, 10)On executing, the above script generates the below output(this output will vary on your system due to randomization) −Grouped Data: uptake ~ conc | Plant   Plant Type Treatment conc uptake ... Read More

How to find the summary by categorical variable in R?

Nizamuddin Siddiqui
Updated on 14-Aug-2021 07:39:18

930 Views

To find the summary by categorical variable, we can follow the below steps −Use inbuilt data sets or create a new data set.Find the summary statistics with by function.Use inbuilt data setLet’s consider mtcars data set in base R − Live Demodata(mtcars) head(mtcars, 25)On executing, the above script generates the below output(this output will vary on your system due to randomization) −                      mpg  cyl disp   hp  drat   wt   qsec vs am gear carb Mazda RX4             21.0 6   160.0 110  3.90 2.620 ... Read More

How to add values in columns having same name and merge them in R?

Nizamuddin Siddiqui
Updated on 14-Aug-2021 07:37:51

2K+ Views

To add values in columns having same name and merge them in R, we can follow the below steps −First of all, create a data frame.Add column values that have same name and merge them by using cbind with do.call.Create the data frameLet's create a data frame as shown below −df

How to create NA column for a contingency table in R?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 15:44:51

469 Views

To create NA column for a contingency table in R, we can follow the below steps −First of all, create a data frame with two columns having some NA values.Create a contingency table for two columns.Create the same table using useNA.Create the data frameLet's create a data frame as shown below − Live Demox

How to find the confusion matrix for linear discriminant analysis in R?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 15:43:34

1K+ Views

To find the confusion matrix for linear discriminant analysis in R, we can follow the below steps −First of all, create a data frame.Create new features using linear discriminant analysis.Find the confusion matrix for linear discriminant analysis using table and predict function.Create the data frameLet's create a data frame as shown below − Live DemoGroup

Advertisements