Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 125 of 196

Convert list with varying number of elements into a data frame.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 689 Views

To convert list with varying number of elements into a data frame in R, we can use stri_list2matrix function of stringi package along with as.data.frame function.For Example, if we have a list called LIST that contains varying number of elements then we can convert it into a data frame by using the below mentioned command −as.data.frame(t(stri_list2matrix(LIST)))Example 1Following snippet creates a sample list −List1

Read More

How to multiply vector values in sequence with matrix columns in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 1K+ Views

To multiply vector values in sequence with matrix columns in R, we can follow the below steps −First of all, create a matrix.Then, create a vector.After that, use t function for transpose and multiplication sign * to multiply vector values in sequence with matrix columns.ExampleCreate the data frameLet’s create a data frame as shown below −M

Read More

How to find the frequency of each value in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 3K+ Views

To find the frequency of each value in an R data frame, we can use table function along with unlist function.For Example, if we have a data frame called df and we want to find the frequency of each value in df then we can use the below command −table(unlist(df))Example 1Following snippet creates a sample data frame −x1

Read More

How to convert alphabets to numbers in data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 435 Views

To convert alphabets to numbers in data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use mutate_each function of dplyr package along with chartr function to convert alphabets to numbers.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) v1

Read More

How to find the percentage of values that lie within a range in R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 3K+ Views

To find the percentage of values that lie within a range in R data frame column, we can follow the below steps −First of all, create a data frame.Then, use sum function along with extreme values for range and length function to find the percentage of values that lie within that range.ExampleCreate the data frameLet’s create a data frame as shown below −Var

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 2K+ 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 Year with the help of command given below −aggregate(df["Demand"],by=df["Year"],sum)Example 1Following snippet creates a sample data frame −Year

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 334 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) var1

Read More

How to save a matrix as CSV file using R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 11K+ 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 −M

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 437 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 create a data frame as shown below −x

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 6K+ 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 command −intersect(df$X,df$Y)Example 1Following snippet creates a sample data frame −x1

Read More
Showing 1241–1250 of 1,958 articles
« Prev 1 123 124 125 126 127 196 Next »
Advertisements