## How to convert a factor that is represented by numeric values to integer or numericvariable in R?

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:43:51

We can convert a factor to integer or numeric variable by using as.numeric function with defining the levels of the factor or by defining the characters of the factorExample> f f [1] 0.323049098020419 0.916131897130981 0.271536672720686 0.462429489241913 [5] 0.657008627429605 0.462429489241913 0.462429489241913 0.212830029195175 [9] 0.271536672720686 0.497305172728375 7 Levels: 0.212830029195175 0.271536672720686 ... ... Read More

## How to replace NA values with zeros in an R data frame?

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:40:55

We can replace all NA values by using is.na functionExample> Data df df V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 1 9 7 3 0 3 7 7 3 9 9 2 9 2 3 0 2 0 1 4 6 7 3 5 0 9 ... Read More

## How to drop data frame columns in R by using column name?

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:39:01

Columns of a data frame can be dropped by creating an object of columns that we want to drop or an object of columns that we want to keep.Example> df keeps df[keeps] Var3 Var4 1 21 31 2 22 32 3 23 33 4 24 34 5 25 35 6 26 36 7 27 37 8 28 38 9 29 39 10 30 40

## How to extract p-value and R-squared from a linear regression in R?

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:36:36

We can use regression model object name with \$r.squared to find the R-squared and a user defined function to extract the p-value.ExampleExtracting R-Squared> x y LinearRegression summary(LinearRegression)\$r.squared [1] 0.2814271Extracting p-value> Regressionp

## How to sort a data frame in R by multiple columns together?

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:33:58

We can sort a data frame by multiple columns using order function.ExampleConsider the below data frame −> df df x1 x2 x3 x4 1 Hi A 4 9 2 Med B 7 5 3 Hi D 5 7 4 Low C 3 4Let’s say we want to sort the ... Read More