Latest questions in Data Analytics

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
468 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
532 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,067 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
699 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,722 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,621 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
613 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,209 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
701 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,390 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,298 views
+1 vote
2 answers

Which function can I use to clear the console in R and RStudio ?

Description                   Windows & Linux           Mac Clear console                      Ctrl+L ...READ MORE

Apr 17, 2018 in Data Analytics by anonymous
74,766 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,540 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,602 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,856 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
623 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,104 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
373 views
+1 vote
2 answers

How can I drop columns by name in a data frame ?

We can Drop Columns by name in ...READ MORE

Apr 14, 2018 in Data Analytics by zombie
• 3,790 points
28,095 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,045 views
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

Apr 14, 2018 in Data Analytics by Sahiti
• 6,370 points
6,370 views
+1 vote
1 answer

How to convert dataframe columns from factors to characters?

To replace all the variables to character ...READ MORE

Apr 13, 2018 in Data Analytics by BHARANI
• 420 points
19,249 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,850 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,180 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,334 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,451 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,865 views
+4 votes
3 answers

How to sum a variable by group in R?

You can also try this way, x_new = ...READ MORE

Aug 1, 2019 in Data Analytics by Cherukuri
• 33,030 points
77,402 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,680 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,921 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,685 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,410 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,856 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
+1 vote
2 answers

How to count the number of elements with the values in a vector?

Use dplyr function group_by(). > n = as.data.frame(num) > ...READ MORE

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

How to group all columns exculding a single column?

You can either use group_by or group_by_at Using ...READ MORE

Apr 12, 2018 in Data Analytics by Sahiti
• 6,370 points
3,227 views
0 votes
2 answers

How to use group by for multiple columns in dplyr, using string vector input in R?

data = data.frame(   zzz11def = sample(LETTERS[1:3], 100, replace=TRUE),   zbc123qws1 ...READ MORE

Aug 6, 2019 in Data Analytics by anonymous
13,694 views
0 votes
1 answer

How to join a list of data frames using map()

You can use reduce set.seed(24) r1 <- map(c(5, 10, ...READ MORE

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

How to apply list to a function which give data frame as output

If you use  tidyverse, you can use ...READ MORE

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

How to extract specific columns from a DataFrame ?

Yes there are so many ways: df[,c(V2,V4)] and another ...READ MORE

Apr 11, 2018 in Data Analytics by DeepCoder786
• 1,720 points
8,393 views
+1 vote
3 answers

How to change column names of a Data frame?

Hi, To change the name of a column ...READ MORE

Oct 30, 2020 in Data Analytics by MD
• 95,440 points
1,391 views
0 votes
1 answer

How to drop data frame columns by name?

Easily you can do it: drops <- c("V2","V4") df1[ ...READ MORE

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

How to replace NA values in a dataframe with Zero's ?

It is simple and easy: df1<-as.data.frame(matrix(sample(c(NA, 1:10), 100, ...READ MORE

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

How to create excellent examples in R?

An excellent example must consist of the ...READ MORE

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

edited Apr 12, 2018 by kappa3010 512 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,467 views
0 votes
2 answers

How to count unique values in R?

You can try this way, as.data.frame(v) %>% count(v) READ MORE

Aug 8, 2019 in Data Analytics by anonymous
6,295 views
0 votes
1 answer

R - Error: Duplicate identifiers for rows

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

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

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

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

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

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

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

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

edited Jun 9, 2020 by Gitika 921 views