Most voted questions in Data Analytics

0 votes
1 answer

How to subset data so that it contains only columns whose names match a condition

You can use grepl on the names ...READ MORE

Apr 27, 2018 in Data Analytics by Sahiti
• 6,370 points
6,050 views
0 votes
2 answers

How to subset rows containing NA in a chosen column of a data frame?

You can give this a try. subset(dataframe, is.na(dataframe$col2)) ...READ MORE

Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
9,857 views
0 votes
1 answer

How to import data from a Json file into R?

Easy and simple: library("rjson") json_file <- "file_name" json_data <- fromJSON(file=json_file)) or ...READ MORE

Apr 26, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,073 views
0 votes
1 answer

What is the standard naming convention for the variables in R?

Use of period separator e.g. product.prices <- c(12.01, ...READ MORE

Apr 25, 2018 in Data Analytics by shams
• 3,670 points
466 views
0 votes
1 answer

How can I define Global Variables in R?

The variables declared inside a function are ...READ MORE

Apr 25, 2018 in Data Analytics by shams
• 3,670 points
5,762 views
0 votes
1 answer

How to wait for a keypress in R?

It is easy by using readline readline(prompt="Press any ...READ MORE

Apr 25, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,474 views
0 votes
1 answer

How to remove all variables except functions in R?

One line that removes all objects except for functions: rm(list ...READ MORE

Apr 25, 2018 in Data Analytics by DeepCoder786
• 1,720 points
3,670 views
0 votes
1 answer

How to set global variables in R

To set global variables, you can use ...READ MORE

Apr 24, 2018 in Data Analytics by kappa3010
• 2,090 points
1,028 views
0 votes
1 answer

How do I find out what directory R has chosen to store packages?

.libPaths() // You can use this command ...READ MORE

Apr 24, 2018 in Data Analytics by zombie
• 3,790 points
396 views
0 votes
1 answer

Why should I use set.seed function() in R?

set.seed(seed) Set the seed of R‘s random number ...READ MORE

Apr 24, 2018 in Data Analytics by zombie
• 3,790 points
1,637 views
0 votes
5 answers

How to remove NA values from a Vector in R?

Hello team, you can use na.omit x <- c(NA, 3, ...READ MORE

Dec 9, 2020 in Data Analytics by anonymous
• 82,880 points
192,423 views
0 votes
1 answer

How to import text file as a single character string?

First way: rd<-readChar("temp.txt",file.info("temp.txt")$size) ...READ MORE

Apr 23, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,061 views
0 votes
1 answer

How to convert tables to a data frame in R ?

> trial.table.df <- as.data.frame(trial.table) //assuming that trial.table ...READ MORE

Apr 20, 2018 in Data Analytics by zombie
• 3,790 points
7,228 views
0 votes
4 answers

How to change font size of text and axes on R plots ?

To change the font size of text ...READ MORE

Dec 16, 2020 in Data Analytics by Gitika
• 65,910 points
115,207 views
0 votes
1 answer

How to prevent row names to be written to a file while using

Easily by: write.csv(df, "temp.csv", row.names=FALSE) READ MORE

Apr 20, 2018 in Data Analytics by DeepCoder786
• 1,720 points
510 views
0 votes
1 answer

How to save a DataFrame in R??

Suppose your DataFrame is named as df: write.csv(df,file="exmp.csv") Then ...READ MORE

Apr 20, 2018 in Data Analytics by DeepCoder786
• 1,720 points
4,846 views
0 votes
1 answer

How can I import multiple .csv files into R ?

## import_multiple_csv_files_to_R # Purpose: Import multiple csv files ...READ MORE

Apr 20, 2018 in Data Analytics by zombie
• 3,790 points
6,006 views
0 votes
1 answer

How to limit output of a dataframe in R?

For randomly sampling a row/cell where a ...READ MORE

Apr 18, 2018 in Data Analytics by kappa3010
• 2,090 points
2,920 views
0 votes
1 answer

How to join columns that are non-NA?

You can match on something like X=X ...READ MORE

Apr 18, 2018 in Data Analytics by Sahiti
• 6,370 points
582 views
0 votes
1 answer

How to find out the package version which is loaded in R?

You can use sessionInfo() to accomplish that. > ...READ MORE

Apr 18, 2018 in Data Analytics by zombie
• 3,790 points
568 views
0 votes
1 answer

How can we trim leading and trailing whitespaces in R?

trimws {base} //Remove Leading/Trailing Whitespace Removes leading and/or ...READ MORE

Apr 18, 2018 in Data Analytics by zombie
• 3,790 points
1,824 views
0 votes
1 answer

Get list of rownames as values after aggregating a dataframe

You can use reshape2 library: library(reshape2) data <- read.table(text="type ...READ MORE

Apr 17, 2018 in Data Analytics by Sahiti
• 6,370 points
465 views
0 votes
1 answer

Reshape data from long to wide format

You can use the reshape function reshape(data, idvar ...READ MORE

Apr 17, 2018 in Data Analytics by nirvana
• 3,130 points
526 views
0 votes
1 answer

How to drop factor levels in a subsetted data frame?

You can use factor(ff) to drop levels ...READ MORE

Apr 17, 2018 in Data Analytics by kappa3010
• 2,090 points

edited Apr 17, 2018 by kappa3010 5,063 views
0 votes
1 answer

Is there any way to check for missing packages and install them in R?

There are 2 options: Either you can use ...READ MORE

Apr 17, 2018 in Data Analytics by nirvana
• 3,130 points
696 views
0 votes
1 answer

Plot two variables as lines on the same graph using ggplot

If you have small number of variables, ...READ MORE

Apr 17, 2018 in Data Analytics by kappa3010
• 2,090 points
4,715 views
0 votes
1 answer

Unload a package without restarting R

Try the below option: detach("package:vegan", unload=TRUE) NOTE: You can ...READ MORE

Apr 17, 2018 in Data Analytics by DataKing99
• 8,240 points
3,612 views
0 votes
1 answer

Check if the object(variable) is defined in R

You can use the exists(): > exists("toFindUnknown") [1] FALSE > ...READ MORE

Apr 17, 2018 in Data Analytics by Sahiti
• 6,370 points
612 views
0 votes
1 answer

How to check if a directory exists and how to create and create if doesn't exist?

You can use showWarnings = FALSE NOTE:  showWarnings ...READ MORE

Apr 17, 2018 in Data Analytics by DataKing99
• 8,240 points
2,198 views
0 votes
1 answer

Find length of string in R

You can try nchar > nchar("fast") [1] 4 > set.seed(10) > ...READ MORE

Apr 17, 2018 in Data Analytics by DataKing99
• 8,240 points
692 views
0 votes
1 answer

Read command line parameters from an R script

Here's an example to explain : Two files ...READ MORE

Apr 17, 2018 in Data Analytics by kappa3010
• 2,090 points
3,382 views
0 votes
1 answer

How can I measuring running time of R Code ?

5 ways to measure running time of ...READ MORE

Apr 17, 2018 in Data Analytics by anonymous
12,284 views
0 votes
1 answer

How to plot side-by-side Plots with ggplot2 in R?

By Using gridExtra library we can easily ...READ MORE

Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by MD 8,534 views
0 votes
3 answers

How to write lines to a text file in R?

sink("outfile.txt") cat("hello") cat("\n" ...READ MORE

May 24, 2019 in Data Analytics by anonymous
18,590 views
0 votes
1 answer

Save a plot as image on the disk using R

Consider for both the situations: 1. Image will ...READ MORE

Apr 14, 2018 in Data Analytics by Sahiti
• 6,370 points
1,852 views
0 votes
1 answer

How to install an R package from source?

If you have your file located locally ...READ MORE

Apr 14, 2018 in Data Analytics by CodingByHeart77
• 3,740 points
621 views
0 votes
1 answer

Concatenate 2 strings in R

You can use the paste() command: You can ...READ MORE

Apr 14, 2018 in Data Analytics by Sahiti
• 6,370 points
1,103 views
0 votes
1 answer

Any built-in function to find mode

You can try out the below code ...READ MORE

Apr 14, 2018 in Data Analytics by kappa3010
• 2,090 points
371 views
0 votes
2 answers

R function for finding the index of an element in a vector?

The function match works on vectors : x <- sample(1:10) x # ...READ MORE

Dec 12, 2020 in Data Analytics by Rajiv
• 8,910 points
56,041 views
0 votes
1 answer

Rename a single column in dataframe using R

colnames(Samp)[2] <- "newname2" This sets the name of ...READ MORE

Apr 13, 2018 in Data Analytics by kappa3010
• 2,090 points
1,848 views
0 votes
1 answer

How to create an empty dataframe?

Initialize with empty vectors: data <- data.frame(Date=as.Date(character()), ...READ MORE

Apr 13, 2018 in Data Analytics by nirvana
• 3,130 points
1,179 views
0 votes
1 answer

How to create dummy variables based on a categorical variable of lists in R?

You can use mtabulate in the following way: library(qdapTools) cbind(data[1], ...READ MORE

Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,740 points
2,329 views
0 votes
2 answers

How to remove rows with missing values (NAs) in a data frame?

Hi, The below code returns rows without ...READ MORE

Aug 20, 2019 in Data Analytics by anonymous
• 33,030 points
14,444 views
0 votes
1 answer

Sample random rows in DataFrame in R

First we should have some data: df1<-data.frame(matrix(rnorm(20), nrow=10)) > ...READ MORE

Apr 13, 2018 in Data Analytics by DeepCoder786
• 1,720 points
7,857 views
0 votes
1 answer

.SD in data.table in R

.SD stands for "Subset of Data.table". The ...READ MORE

Apr 13, 2018 in Data Analytics by nirvana
• 3,130 points
6,674 views
0 votes
1 answer

Working of ggplot scale_continuous 'expand' argument

According to the document if you set limits manually, ...READ MORE

Apr 13, 2018 in Data Analytics by DataKing99
• 8,240 points
2,914 views
0 votes
1 answer

What is the difference between [] and [[]] notations to access the elements of a list or dataframe in R?

R provides 3 basic indexing operators. Refer ...READ MORE

Apr 12, 2018 in Data Analytics by kappa3010
• 2,090 points
2,684 views
0 votes
1 answer

How to find out the sum/mean for multiple variables per group in R?

You can use the reshape2 package for ...READ MORE

Apr 12, 2018 in Data Analytics by DataKing99
• 8,240 points
3,402 views
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

Apr 12, 2018 in Data Analytics by nirvana
• 3,130 points

edited Apr 12, 2018 by nirvana 21,852 views
0 votes
1 answer

How to merge data frames using joins?

You can use the merge function with ...READ MORE

Apr 12, 2018 in Data Analytics by kappa3010
• 2,090 points
655 views