Server Side Programming Articles

Page 1124 of 2109

How to select rows of an R data frame that are non-NA?

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

To select rows of an R data frame that are non-Na, we can use complete.cases function with single square brackets. For example, if we have a data frame called that contains some missing values (NA) then the selection of rows that are non-NA can be done by using the command df[complete.cases(df), ].Example1Consider the below data frame −> x1 x2 x3 df1 df1Output   x1 x2 x3 1   1 NA NA 2  NA  5  3 3   1  5 NA 4   1 NA NA 5  NA  5 NA 6  NA  5  3 7  NA  5 NA 8   1 NA ...

Read More

How to display the data frame summary in vertical order in R?

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

To display the data frame summary in vertical order, we can use lapply and cbind function along with the summary function. For example, if we have a data frame called df then the summary of df in vertical order can be found by using the below command −lapply(df, function(x) cbind(summary(x)))Example1Consider the below data frame −> x1 x2 x3 x4 x5 df1 df1Output   x1 x2 x3 x4 x5 1   4  0  2  2  6 2   7  2  4  1  7 3   7  2  3  3  6 4   4  0  4  5  2 5   5  2  2 ...

Read More

How to create a list of regression models for predefined vectors in R?

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

To create a list of regression models for predefined vectors, we can create a blank list and then use the for loop to create the list of regression models. For example, if we have two vectors say x and y, and we want to create a list of regression model between x and y then we create a blank list using list() and perform for loop a particular number of times as shown in the below examples.Example1x

Read More

How to find the proportion of each value for a cross tab obtained from a data frame in R?

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

To find the proportion of each value for a cross tab obtained from a data frame, we can use prop.table function. Suppose we have a data frame called df that contains three columns, two categorical say C1 and C2 and one numerical say Y then the cross tab will be created by using the command xtabs(Y~.,df). Now the proportion of each value can be found by using prop.table(xtabs(Y~.,df),1).Example1Consider the below data frame −f1

Read More

How to check if a time series is stationary in R?

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

To check if a time series is stationary, we can use Dickey-Fuller test using adf.test function of tseries package. For example, if we have a time series object say TimeData then to check whether this time series is stationary or not we can use the command adf.test(TimeData).Example1x1

Read More

How to apply multiple AND conditions to a data frame in R?

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

To apply multiple conditions to a data frame, we can use double and sign that is &&. For example, if we have a data frame called df that contains three columns say x, y, z and we want to add a value to all columns if first element in z equals to 5 then it can be done by using the command −if(df$x && df$y && df$y == 5){    df$x = df$x+10    df$y = df$y+10    df$z = df$z+10 }Example1Consider the below data frame −x1

Read More

How to find the high leverage values for a regression model in R?

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

To find the high leverage values for a regression model, we first need to find the predicted values or hat values that can be found by using hatvalues function and then define the condition for high leverage and extract them. For example if we have a regression model say M then the hat values can be found by using the command hatvalues(M), now to find the high leverage values that are greater than 0.05 can be found by using the below code −which(hatvalues(M)>0.05)Example1Consider the below data frame −x1

Read More

How to add a variable description in R?

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

To add a variable description in R, we can use comment function and if we want to have a look at the description then structure call of the data frame will be used. For example, if we have a data frame say df that contains a column x then we can describe x by using the command comment(df$x)

Read More

How to convert a list to JSON in R?

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

To convert a list to JSON, we can use toJSON function of jsonlite package. For example, if we have a list called LIST then it can be converted to a JSON by using the command toJSON(LIST,pretty=TRUE,auto_unbox=TRUE). We need to make sure that the package jsonlite is loaded in R environment otherwise the command won’t work.ExampleList

Read More

How to find the object size in R?

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

To find the object size in R, we can use object.size function. For example, if we have a data frame called df then the size of df can be found by using the command object.size(df). Similarly, if we have a vector say x then it’s size can be found using object.size(x) and for a matrix M it can be object.size(M).Example1Consider the below data frame −x

Read More
Showing 11231–11240 of 21,090 articles
Advertisements