Nizamuddin Siddiqui has Published 2303 Articles

How to create a frequency table of a vector that contains repeated values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:57:49

750 Views

We can do this by using table function with as.data.frameExample> X as.data.frame(table(X)) X Freq 1 21 2 2 23 3 3 24 1 4 25 5 5 34 2 6 47 2 7 64 1 8 69 5 9 70 1

How to change the column names and row names of a data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:56:42

604 Views

We can colnames function to change the column names and rownames function to change the row names.Example> df df ID Salry 1 1 10000 2 2 30000 3 3 22000 4 4 27000 5 5 18000 > colnames(df) df EmployeeID Salary 1 1 10000 2 2 30000 3 3 22000 4 4 27000 5 5 18000 > rownames(df)

How to check which packages are loaded in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

4K+ Views

We can do this by using sessionInfo().> sessionInfo() R version 3.6.1 (2019-07-05) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363) Matrix products: default Random number generation: RNG: Mersenne-Twister Normal: Inversion Sample: Rounding locale: [1] LC_COLLATE=English_India.1252 LC_CTYPE=English_India.1252 [3] LC_MONETARY=English_India.1252 LC_NUMERIC=C [5] LC_TIME=English_India.1252 attached base packages: [1] stats graphics grDevices ... Read More

How to create an empty data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:53:45

302 Views

We can create an empty data frame as follows −> df str(df) 'data.frame': 0 obs. of 5 variables: $ Income : num $ Age : int $ EducationLevel: Factor w/ 0 levels: $ MaritalStatus : logi $ StateLiving : chrWe can edit this data frame by using −> edit(df)This ... Read More

How to convert a list to a data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:50:28

269 Views

Consider the below list −> List df df X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 1 x c t g d l j y i q 2 s k u j i w x o p n 3 h p e c y m o ... Read More

How to check if a vector contains a given value in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

515 Views

We can use match %in% to check whether a vector contains a given value of notExample> x 1%in%x [1] TRUE > 10%in%x [1] TRUE > 99%in%x [1] TRUE > 1024%in%x [1] TRUE > 100%in%x [1] FALSEWe can also do this for checking the common values between two vectors.Example> x ... Read More

How to drop factor levels in subset of a data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:47:10

799 Views

There are two ways to do drop the factor levels in a subset of a data frame, first one is by using factor function and another is by using lapply.Example> df levels(df$alphabets) [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" > subdf levels(subdf$alphabets) [1] "a" ... Read More

How to create two line charts in the same plot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Jul-2020 12:45:16

213 Views

We can do this by using lines function after plotting the first chart.Example> x X1 X2 plot(x, X1, type="l",col="red", ylab="X") > lines(x, X2, col="green")

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

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

140 Views

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

Nizamuddin Siddiqui

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

412 Views

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

Advertisements