Found 2038 Articles for R Programming

How to deal with hist.default, 'x' must be numeric in R?

Nizamuddin Siddiqui
Updated on 09-Nov-2021 08:07:20

8K+ Views

The error hist.default, 'x' must be numeric occurs when we pass a non-numerical column or vector to the hist function. If we have a non-numerical column in a data frame or a non-numerical vector and we want to create the histogram of that data can be created with the help of barplot and table function.Check out the below given Exampleto understand how it can be done.ExampleFollowing snippet creates a sample data frame −x

How to create a column of log with base 2 in data frames stored in R list?

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:58:37

120 Views

To create a column of log with base 2 in data frames stored in R list, we can follow the below steps −First of all, create a list of data frames.Then, use lapply function to create a column of log with base 2 in data frames stored in the list.ExampleCreate the list of data framesUsing data.frame function to create data frames and list function to create the list of those data frames −df1

How to create a column of natural log in data frames stored in R list?

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:54:53

113 Views

To create a column of natural log in data frames stored in R list, we can follow the below steps −First of all, create a list of data frames.Then, use lapply function to create a column of natural log in data frames stored in the list.ExampleCreate the list of data framesUsing data.frame function to create data frames and list function to create the list of those data frames −df1

Create a data frame with numerical as well as factor columns in R.

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:59:36

912 Views

To create a data frame with numerical as well as factor columns in R, we simply need to add factor function before factor columns and numerical columns will be created without mentioning any specific characteristics, the values of numerical columns just need to be numerical in nature.Example 1Following snippet creates a sample data frame df1 with factor and numerical column −Gender

How to create a column of raise to the power 3 in data frames stored in R list?

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:51:01

87 Views

To create a column of raise to the power 3 in data frames stored in R list, we can follow the below steps −First of all, create a list of data frames.Then, use lapply function to create a column of raise to the power 3 in data frames stored in the list.ExampleCreate the list of data framesUsing data.frame function to create data frames and list function to create the list of those data frames −df1

How to create a column of square root in data frames stored in R list?

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:47:55

114 Views

To create a column of square root in data frames stored in R list, we can follow the below steps −First of all, create a list of data frames.Then, use lapply function to create a column of square root in data frames stored in the list.ExampleCreate the list of data framesUsing data.frame function to create data frames and list function to create the list of those data frames −df1

How to randomize rows of a matrix in R?

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:49:37

2K+ Views

To randomize rows of a matrix in R, we can use sample function along with nrow function to get the random rows and then subset the matrix with single square brackets.For example, if we have a matrix called M then randomization of rows in M can be done by using the command given below − Random_rows

How to create a column of square in data frames stored in R list?

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:45:38

77 Views

To create a column of square in data frames stored in R list, we can follow the below steps −First of all, create a list of data frames.Then, use lapply function to create a column of square in data frames stored in the list.ExampleCreate the list of data framesUsing data.frame function to create data frames and list function to create the list of those data frames −df1

How to split a data frame by column in R?

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:44:52

3K+ Views

If we have a data frame column that contains some duplicate values or represent categories then we might want to split the data frame based on that column.For example, if we have a data frame called df that contains a column say Col then we can split the data frame by Col by using the command given below −split(df,df$Col)Example 1Following snippet creates a sample data frame −Group

Replace numerical column values based on character column values in R data frame.

Nizamuddin Siddiqui
Updated on 09-Nov-2021 07:45:35

826 Views

To replace numerical column values based on character column values in R data frame, we can use subsetting with single square brackets and %in% operator and the value will be assigned with

Advertisements