128 Answered Questions for the topic R

R

09/28/19

Choosing between qplot() and ggplot() in ggplot2?

I'm starting to use the great `ggplot2` package for plotting in R, and one of the first things I ask myself before each plot is *"well, will I use `qplot` or `ggplot` ?"*I understand that `qplot`... more
R

09/28/19

Find file name from full file path?

Is there a way to extract the file name from the file full path (part of a file path) without the hassle of manipulating string?The equivalent in Java would be: File f = new File... more
R

09/27/19

How can I do the same thing to multiple data sets?

R

09/27/19

What does "not run" mean in R help pages?

Sometimes on an R help page the phrase "not run" appears in comments. Check out this from the help page for "with()": Examples require(stats); require(graphics) #examples from glm: **##... more
R

09/27/19

Count number of objects in list?

Anyone know an R function that will return the number of items in a list?
R

09/26/19

Rotating x axis labels in R for barplot?

I am trying to get the x axis labels to be rotated 45 degrees on a barplot with no luck. This is the code I have below: barplot(((data1[,1] - average)/average) * 100, srt = 45, ... more
R

09/26/19

Why is `[` better than `subset`?

When I need to filter a data.frame, i.e., extract rows that meet certain conditions, I prefer to use the `subset` function: subset(airquality, Month == 8 & Temp > 90)Rather than the `[`... more
R

09/26/19

How can I plot with 2 different y-axes?

I would like superimpose two scatter plots in R so that each set of points has its own (different) y-axis (i.e., in positions 2 and 4 on the figure) but the points appear superimposed on the same... more
R

09/25/19

Fastest way to find second (third...) highest/lowest value in vector or column?

R offers max and min, but I do not see a really fast way to find the another value in the order apart from sorting the whole vector and than picking value x from this vector.Is there a faster way... more
R

09/25/19

View entire data frame when wrapped in tbl_df?

`tibble` (previously `tbl_df`) is a version of a data frame created by the `dplyr` data frame manipulation package in R. It prevents long table outputs when accidentally calling the data frame.Once... more
R

09/22/19

Determining memory usage of objects?

I'd like to work out how much RAM is being used by each of my objects inside my current workspace. Is there an easy way to do this?
R

09/20/19

Geometric Mean: is there a built-in?

I tried to find a built-in for geometric mean but couldn't.(Obviously a built-in isn't going to save me any time while working in the shell, nor do I suspect there's any difference in accuracy; for... more
R

09/19/19

Can dplyr join on multiple columns or composite key?

I realize that `dplyr` v3.0 allows you to join on different variables:`left_join(x, y, by = c("a" = "b")` will match `x.a` to `y.b`However, is it possible to join on a combination of variables or... more
R

09/19/19

What does %>% mean in R?

I am following this example, the *server.R*, [file is here](https://github.com/wch/movies/blob/master/server.R#L32).I plan to do a similar filter, but am lost as to what `%>%` does. # Apply... more
R

09/18/19

How to read data when some numbers contain commas as thousand separator?

I have a csv file where some of the numerical values are expressed as strings with commas as thousand separator, e.g. `"1,513"` instead of `1513`. What is the simplest way to read the data into R?I... more
R

09/18/19

Incomplete final line' warning when trying to read a .csv file into R?

I'm trying to read a .csv file into R and upon using this formula: pheasant<-read.table(file.choose(),header=TRUE,sep=",")I get this warning message: "incomplete final line found by... more
R

09/16/19

How to remove all whitespace from a string?

So `" aa bb 11 22 33 "` will become `"aabb112233"`. How can I achieve this?
R

09/15/19

Quickly reading very large tables as dataframes?

I have very large tables (30 million rows) that I would like to load as a dataframes in R. `read.table()` has a lot of convenient features, but it seems like there is a lot of logic in the... more
R

09/12/19

How to solve and plot differential equations in R?

Taken from Sal Khan's lecture https://www.youtube.com/watch?v=oiDvNs15tkE of the Khan academy, if I know that dN/dt=rN(1-(N/K)) (the logistic differential equation) How can I solve for N and plot... more
R

09/12/19

Fitting a density curve to a histogram in R?

Is there a function in R that fits a curve to a histogram?Let's say you had the following histogram hist(c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4)))It looks... more
R

09/11/19

Summarizing multiple columns with dplyr?

I'm struggling a bit with the dplyr-syntax. I have a data frame with different variables and one grouping variable. Now I want to calculate the mean for each column within each group, using dplyr... more
R

09/10/19

How to disable "Save workspace image?" prompt in R?

When I exit the interactive R shell, it displays an annoying prompt every time:<pre>>>Save workspace image? [y/n/c]: n</pre>I'm always answering "no" to it, because if I wished to... more
R

09/10/19

Omit rows containing specific column of NA?

I want to know how to omit `NA` values in a data frame, but only in some columns I am interested in.For example, DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA), z=c(NA, 33, 22))but I only... more
R

09/10/19

Remove duplicated rows using dplyr?

I have a data.frame like this - set.seed(123) df = data.frame(x=sample(0:1,10,replace=T),y=sample(0:1,10,replace=T),z=1:10) > df x y z 1 0 1 1 2 1 0 2 3 0 1 3 ... more
R

09/09/19

How can I remove an element from a list?

I have a list and I want to remove a single element from it. How can I do this?I've tried looking up what I think the obvious names for this function would be in the reference manual and I haven't... more

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.