Found 2038 Articles for R Programming

How to find the name of the author of a package in R?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 15:01:28

322 Views

There can be multiple authors of a package in R and we might want to use their name if we are using their package in our publication for research, books, courses or any other type of content. Therefore, it is required to find out all the authors who contributed to a particular package and this can be done by using citation function with package name as shown in the below examples.Examplecitation("ggplot2")To cite ggplot2 in publications, please use −H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.A BibTeX entry for LaTeX users is@Book{,    author = {Hadley Wickham}, ... Read More

How to find the variance of row elements of a matrix in R?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 14:56:49

1K+ Views

Finding the variance of columns is a common task in data analysis but often data is provided in wide format instead of long format, therefore, the cases are represented vertically and the variables are aligned horizontally and this data could be available in matrix or any other form. Therefore, the variance can be easily found by using apply function.Example Live DemoM1

How to create a predictive linear regression line for a range of independent variable in base R?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 14:51:13

247 Views

If we want to create a regression line inside scatterplot then lines function can be used with the linear model function lm but if we want to do it for a particular range of independent variable then this range needs to be defined and passed within the lines function. Check out the below example of linear regression model that considers a range of independent variable for prediction.Consider the below vectors −Examplestrsplit(x6,"[*]")OutputDefining the range of x −Range_of_x

How to separate strings in R that are joined with special characters?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 14:49:10

114 Views

When we deal with text data it is difficult to make it clean and one of the most of basic problem with this type of data is that the values are separated with some unique characters such as special characters. For this purpose, we can use strsplit function that makes it easy to do the separation among text values. Check out the examples below to understand how it can be done.Example Live Demox1

How to check whether a string is in lowercase or uppercase in R?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 14:46:44

3K+ Views

We can use str_detect function to check whether a single string or a vector of strings is in lowercase or uppercase. Along with str_detect function, we need to use either upper or lower to check whether the string is in lowercase or uppercase and the output will be returned in TRUE or FALSE form, if the string will be in lowercase and we pass lower with str_detect function then the output will be TRUE and vice-versa.Example Live Demox1

How to find the rank of a vector elements in R from largest to smallest?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 14:43:06

1K+ Views

To find the rank of a vector of elements we can use rank function directly but this will result in ranks from smallest to largest. For example, if we have a vector x that contains values 1, 2, 3 in this sequence then the rank function will return 1 2 3. But if we want to get ranks from largest to smallest then it would be 3 2 1 and it can be done in R as rank(-x).Example Live Demox1

How to change column names to capital letters from lower case or vice versa in R?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 14:42:39

979 Views

Mostly, we get data that contain column names in lowercase or just first letter is in upper case. If we want to convert those column names to all capital letter words or uppercase then toupper function can be used to the names of the columns. This can be done by using the below syntax −Syntaxnames(“data_frame_name”)

How to extract odds ratio of intercept and slope coefficient from simple logistic model in R?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 14:18:22

241 Views

To create the simple logistic model, we need to use glm function with family = binomial because the dependent variable in simple logistic model or binomial logistic model has two categories, if there are more than two categories then the model is called as multinomial logistic model. If we want to extract the odds ratio of slope and intercept from the simple logistic model then exp function needs to be used with model object as shown in the below examples.Example Live Demoset.seed(999) x1

How to repeat a column of a data frame and join it with another data frame in R by rows?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 14:01:10

183 Views

Suppose we have a data frame df1 that contains 5 columns and another data frame df2 that contains only column but the data type of the columns in both the data frames is same. Now we might want to add the column of the second data frame starting at the end of the rows of the first data frame by creating the same number of columns as in first data frame. This might be required by researchers to understand the impact of an external variable on the result of the analysis and it can be done with the help of ... Read More

How to create random values in R up to a range of values starting from 1?

Nizamuddin Siddiqui
Updated on 16-Oct-2020 13:56:02

137 Views

Random sampling is a technique used by almost every researcher, analyst, financial analyst, data scientist, or even a leader and if we way that almost everyone uses it at least once in a lifetime then it won’t be surprise. Because we use it in one or the way in our life even if we don’t know about it. To take a random sample or creating random values up to a range of values starting from 1, we can simply use sample function in R. Checkout below examples to understand how this function works for sampling with replacement.Example Live Demosample(100)Output[1] 17 76 ... Read More

Advertisements