Separate Two Values in Single Column in R Data Frame

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:40:30

1K+ Views

To separate two values in single column in R data frame, we can follow the below steps −First of all, create a data frame.Then, use separate function from tidyr package to separate the values in single column.ExampleCreate the data frameLet’s create a data frame as shown below −df

Standardize Columns in R Data Frame with Categorical Data

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:37:31

242 Views

To standardize columns if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to standardize columns if some columns are categorical.ExampleCreate the data frameLet’s create a data frame as shown below −Level

Frequency of Unique and Missing Values in R Data Frame

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:36:06

516 Views

To find the frequency of unique values and missing values for each column in an R data frame, we can use apply function with table function and useNA argument set to always.For Example, if we have a data frame called df then we can find the frequency of unique values and missing values for each column in df by using the below mentioned command −apply(df,2,table,useNA="always")Example 1Following snippet creates a sample data frame −x1

Convert First Letter to Capital in R Data Frame

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:34:13

2K+ Views

To convert first letter into capital in single column data frame in R, we can follow the below steps −First of all, create a data frame with string column.Then, use capitalize function from R.utils package to convert first letter into capital in single column.ExampleCreate the data frameLet’s create a data frame as shown below −Names

Convert First Letter to Capital in Data Table Object in R using dplyr

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:31:27

185 Views

To convert first letter into capital in single column data.table object in R, we can follow the below steps −First of all, create a data.table object with string column.Then, use sub function along with mutate function of dplyr package to convert first letter into capital in string column.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) Names

Frequency of Unique Values for Each Column in an R Data Frame

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:31:12

766 Views

To find the frequency of unique values for each column in an R data frame, we can use apply function with table function.For Example, if we have a data frame called df then we can find the frequency of unique values for each column in df by using the below mentioned command −apply(df,2,table)Example 1Following snippet creates a sample data frame −x1

Find Row Median of Columns with Same Name in Data Table Object in R

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:29:47

158 Views

To find the row median of columns having same name in data.table object in R, we can follow the below steps −First of all, create a data.table with some columns having same name.Then, use tapply along with colnames and median function to find the row median of columns having same name.ExampleCreate the data.tableLet’s create a data.table as shown below −library(data.table) DT

Create Repeated Values Column with Random Selection in R Data Frame

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:25:00

1K+ Views

To generate a repeated values column with each value in output selected randomly in R data frame, we can use replicate function. The replicate function will repeat the vector values up to the number of times we want and each value will be randomly selected. To understand how it works, check out the below examples.Example 1Using replicate function to create a data frame df with normal random variable column of size 25 −x

Create a Vector of Matrices in R

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:24:13

578 Views

As of now it is not possible to create a vector of matrices in R. If we want to do it, we should prefer a list, hence we can create a list with matrices.For Example, if we have matrices say M1, M2, and M3 and we want to create a list of these matrices then we can use the below given command −list(M1,M2,M3)ExampleTo create a vector of matrices in R, use the following snippet −List

Find Index of Values in Data Table Column in R

Nizamuddin Siddiqui
Updated on 10-Nov-2021 06:23:00

1K+ Views

To find the index of values in data.table object column in R if they occur once, we can follow the below steps −First of all, create a data.table object.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 occur once.Example 1Create the data.table objectLet’s create a data.table object as shown below −library(data.table) x

Advertisements