R Programming Articles

Page 30 of 174

How to create boxplot in base R with higher width of the box lines?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 273 Views

To create boxplot in base R with higher width of the box lines, we can use the boxlwd argument inside boxplot function. For example, if we have a vector called x then we can create the boxplot with higher width of the box lines using the command −boxplot(x,boxlwd=5)Examplex

Read More

How to display p-value with coefficients in stargazer output for linear regression model in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

To display p-value in stargazer output for linear regression model, we can use the report argument. For example, if we have a model called RegressionModel then to display the p-value with coefficients can be done by using the below command −stargazer(RegressionModel,type="text",report=("vc*p"))ExampleConsider the below data frame −x1

Read More

How to create a frequency column for categorical variable in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 6K+ Views

To create a frequency column for categorical variable in an R data frame, we can use the transform function by defining the length of categorical variable using ave function. The output will have the duplicated frequencies as one value in the categorical column is likely to be repeated. Check out the below examples to understand how it can be done.ExampleConsider the below data frame −Country

Read More

How to replace a particular value in R data frame with a new value?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To replace a particular value in R data frame with a new value, we can use ifelse function where the new value will be placed after the condition and if the column values do not match the condition then the same column will be placed. For example, if we have a data frame called df that contains a column x having 20 values and some of them are 5 and if we want to replace 5 with 2 then we can use the command df$x

Read More

How to perform paired t test for multiple columns in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

When we have a factor column in an R data frame that has two levels and multiple numerical columns then we can apply paired-test on this data frame but the data must be collected for same subjects, otherwise it will not be a paired data. The t.test application on the data discussed here can be done by using the command lapply(df[-1], function(x) t.test(x~df$group)), where group is the factor column and lies at the first position in the data frame, x contains all the numerical columns in the data frame, and all these columns are stored in data frame called df.ExampleConsider ...

Read More

What to do if numeric values are being read as character in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

If the numeric values are being read as character then we need to convert them into numeric values by using the function as.numeric. For example, if we have a data frame called df that contains a column say x which has numerical values stored in character format then we can convert them into numeric values using the command as.numeric(df$x).ExampleConsider the below data frame −x1

Read More

How to create a table for the number of unique values in list of vectors in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 270 Views

To create a table for the number of unique values in list of vectors, we can use mtabulate function of qdapTools package. For example, if we have a list of vectors say LIST that contains some vectors then the table for the number of unique values in the vectors of LIST can be found by using mtabulate(LIST).ExampleConsider the below list −x1

Read More

How to find the position of odd numbers in an R vector?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

To find the position of odd numbers in an R vector, we can find the position of values that are divisible by 2 with the help of which function. For example, if we have a vector called x then we can find the position of odd numbers using the command which(x%%2==1). Check out the below examples to understand how it works.Examplex1

Read More

How to add name to data frame columns in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

A data frame can be created by using data.frame function but in this case R generates the column names using the values we pass for the data. For example, if we pass a probability distribution as shown in the below examples then its name will be there. If we want to change those names then setNames function can be used along with the data frame name.Exampledf1

Read More

How to convert an array into a matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 5K+ Views

To convert an array into a matrix in R, we can use apply function. For example, if we have an array called ARRAY that contains 2 array elements then we can convert this array into a single matrix using the command apply(ARRAY,2,c). We need to understand the dimension of the array making the conversion otherwise the output will not be as expected.ExampleConsider the below array −x1

Read More
Showing 291–300 of 1,740 articles
« Prev 1 28 29 30 31 32 174 Next »
Advertisements