tagged [r]
Convert a dataframe to a vector (by rows)
Convert a dataframe to a vector (by rows) I have a dataframe with numeric entries like this one I was able to get it using the following, but I guess there should be a much more elegant way ``` X
Order discrete x scale by frequency/value
Order discrete x scale by frequency/value I am making a dodged bar chart using ggplot with discrete x scale, the x axis are now arranged in alphabetical order, but I need to rearrange it so that it is...
Plot two graphs in a same plot
Plot two graphs in a same plot I would like to plot y1 and y2 in the same plot. ``` x
How to import multiple .csv files at once?
How to import multiple .csv files at once? Suppose we have a folder containing multiple data.csv files, each containing the same number of variables but each from different times. Is there a way in R ...
Only read selected columns
Only read selected columns Can anyone please tell me how to read only the first 6 months (7 columns) for each year of the data below, for example by using `read.table()`? ``` Year Jan Feb Mar Apr May...
How to read data when some numbers contain commas as thousand separator?
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"`...
Subset / filter rows in a data frame based on a condition in a column
Subset / filter rows in a data frame based on a condition in a column Given a data frame "foo", how can I select only those rows from "foo" where e.g. `foo$location = "there"`? Desired
Fitting a density curve to a histogram in R
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 It looks normal, but it's skewed. I want to fit a norma...
- Modified
- 16 Nov at 16:38
What does "The following object is masked from 'package:xxx'" mean?
What does "The following object is masked from 'package:xxx'" mean? When I load a package, I get a message stating that: For example, if I load [testthat](http://www.rdocumentation.org/packages/testth...
Side-by-side plots with ggplot2
Side-by-side plots with ggplot2 I would like to place two plots side by side using the [ggplot2 package](http://crantastic.org/packages/ggplot2), i.e. do the equivalent of `par(mfrow=c(1,2))`. For exa...
- Modified
- 20 Dec at 16:48
How to subtract/add days from/to a date?
How to subtract/add days from/to a date? I'm trying to build folders to store data pulls. I want to label the folders with the day of that data in the pull. Ex. I pull 5 days ago data from mysql i wan...
Sort (order) data frame rows by multiple columns
Sort (order) data frame rows by multiple columns I want to sort a data frame by multiple columns. For example, with the data frame below I would like to sort by column 'z' (descending) then by column ...
Update R using RStudio
Update R using RStudio How can I update R via RStudio?
Re-ordering factor levels in data frame
Re-ordering factor levels in data frame I have a data.frame as shown below: The task column takes only six different values, which are treated as factors, and are ordered by R as: "back", "down", "fro...
Combine two or more columns in a dataframe into a new column with a new name
Combine two or more columns in a dataframe into a new column with a new name For example if I have this: Then how do I combine the two columns `n` and `s` into a new column named `x` such that it look...
- Modified
- 2 May at 06:55
Formatting Decimal places in R
Formatting Decimal places in R I have a number, for example 1.128347132904321674821 that I would like to show as only two decimal places when output to screen (or written to a file). How does one do t...
- Modified
- 17 Sep at 19:23
Plotting two variables as lines using ggplot2 on the same graph
Plotting two variables as lines using ggplot2 on the same graph A very newbish question, but say I have data like this: ``` test_data
- Modified
- 2 May at 11:37
How to make a great R reproducible example
How to make a great R reproducible example When discussing performance with colleagues, teaching, sending a bug report or searching for guidance on mailing lists and here on Stack Overflow, a [reprodu...
Euclidean distance of two vectors
Euclidean distance of two vectors How do I find the Euclidean distance of two vectors: ``` x1
- Modified
- 5 Oct at 09:27
Error: unexpected symbol/input/string constant/numeric constant/SPECIAL in my code
Error: unexpected symbol/input/string constant/numeric constant/SPECIAL in my code I received one of these errors. ``` Error: unexpected symbol in "" Error: unexpected input in "" Error: unexpected...
Combine a list of data frames into one data frame by row
Combine a list of data frames into one data frame by row I have code that at one place ends up with a list of data frames which I really want to convert to a single big data frame. I got some pointers...
How to unload a package without restarting R
How to unload a package without restarting R I'd like to unload a package without having to restart R (mostly because restarting R as I try out different, conflicting packages is getting frustrating, ...
How do I convert certain columns of a data frame to become factors?
How do I convert certain columns of a data frame to become factors? > [identifying or coding unique factors using R](https://stackoverflow.com/questions/5798206/identifying-or-coding-unique-factors-u...