I have a pre-binned frequency table for a rather large dataset. That is, a single column vector of bins and a single column vector of counts associated with those bins. I'd like R to plot a histogram of this data by doing further binning and summing the existing counts. For example, if in the pre-binned data I have something like [(0.01,...
What I'd like to do is take this matrix:
> partb
0.5 1.5 1a 1b -2 -3
A1FCLYRBAB430F 0.26 0.00 0.74 0.00 0.00 0.00
A1SO604B523Q68 0.67 0.33 0.00 0.00 0.00 0.00
A386SQL39RBV7G 0.00 0.33 0.33 0.33 0.00 0.00
A3GTXOXRSE74WD 0.41 0.00 0.08 0.03 0.05 0.44
A3OOD9IMOHPPFQ 0.00 0.00 0.33 0.00 0.33 0.33
A8AZ39QM2A9SO 0.1...
Hey, I'm trying to generate a list of primes below 1 billion. I'm trying this, but this kind of structure is pretty shitty. Any suggestions?
a <- 1:1000000000
d<- 0
b <- for (i in a) {for (j in 1:i) {if (i %% j !=0) {d <- c(d,i)}}}
...
I'm examining some biological data which is basically a long list (a few million values) of integers, each saying how well this position in the genome is covered. Here is a graphical example for a data set:
I would like to look for "valleys" in this data, that is, regions which are significantly lower than their surrounding environmen...
I am analyzing a dataset in which data is clustered in several groups (towns in regions). The dataset looks like:
R> df <- data.frame(x = rnorm(10),
y = 3*rnorm(x),
groups = factor(sample(c('0','1'), 10, TRUE)))
R> head(df)
x y groups
1 -0.8959 1.54 1
2 -0.1008 -2.73 1
...
I have a melted data.frame, dput(x), below:
## dput(x)
x <- structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
4L, 4L), .Label = c("a", "b", "c", "d"), class = "factor"),
value = structure(c(1L,
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, ...
I searched for this and found that with {grid} there are ways to rotate an image, and that for some plots you can play with their rotation (for example plot(x,y) instead of plot(y,x)).
However, I want to know if there is a generic method to rotate a plot in R (one that would work for ANY plot generated in base graphics) ?
...
I am trying to export a data.frame to a csv with utf-8 encoding. I have tried generating the file with write.csv with no success and the help(write.csv) did not mention any specific advice on creating that specific output. Here is my current export line.
write.csv(prod_out, file="product_output.csv",append=FALSE,eol="\r")
Any advice y...
Hi
When using aggregate, how can I make reference to a previous period within the function?
For example if aggregating by days how can make reference to the previous day from the next day in order to calculate the function.
For example if I had a one year hourly time series and I like to calculate the maximum of one day minus the mini...
This is comp sci 101 stuff, but I couldn't find an answer applicable to R (or matlab).
I have a for loop that I want to initialize with a first guess (all zeros here, but maybe something else later), but I want to keep updating with each iteration. What I have below works, but it kind of clunky and embarrassing.
I would like to avoid t...
I'm trying to fit a function consisting of several gauss bells to some experimental data. The method used is the nls function from R. But it is difficult to get the initial guess good enough, such that the method can converge.
Is it possible to visualize the initial guess BEFORE the optimization routine is called?
The code I'm working ...
What is the quickest/best way to change a large number of columns to numeric from factor?
I used the following code but it appears to have re-ordered my data.
> head(stats[,1:2])
rk team
1 1 Washington Capitals*
2 2 San Jose Sharks*
3 3 Chicago Blackhawks*
4 4 Phoenix Coyotes*
5 5 New Jersey Devils*
6...
I am using read.csv to import a file that contains some columns with empty cells. I need these cells to remain empty and not contain any values.
However, an NA is getting added everytime I import. I have tried variations of na.strings (like na.strings="NULL" or na.strings="") to no avail.
Is there a simple way to force the observatio...
Imagine I have a data frame with 2 columns
Id Value
12 13
32 3
6022 11
9142 231
12 23
119 312
...
and I want to get the mean value for each "Id". Do you know of any fast way of doing this?
...
Which of the dataset formats listed at this link is the easiest to load for processing in R? A few minutes with a text editor should be enough to turn the text version into literal data but can one of the other forms be loaded in less than O(n) user effort?
I've found this laundry list of IO options but it dosn't seem especially helpful...
I have a vector of integers, e.g.: 2,8,11,19.
I would like to plot a line of length e.g. 20 then plot a dot for each value that exist in the list (at some constant height), so I get something like this:
-+-----+--+-------+-
...
I'm running cor() on a data.frame with all numeric values and I'm getting this as the result:
price exprice...
price 1 NA
exprice NA 1
...
So it's either 1 or NA for each value in the resulting table. Why are the NAs showing up instead of valid correlations?
...
The discussion in this question is the direct cause for me asking this question. The more general reason is the fact that I often have to explain R use to people that are only familiar with SPSS. I know most of the basics of SPSS, as we still use it in the base course statistics. But as I'm more of an R guy, it's difficult to know how SP...
Hello,
I am currently using this code to input data from numerous files into R:
library(foreign)
setwd("/Users/ericbrotto/Desktop/A_Intel/")
filelist <-list.files()
#assuming tab separated values with a header
datalist = lapply(filelist, function(x)read.table(x, header=T, sep=";", comment.char=""))
#assuming the same header/c...
Hi all,
I apologize if this has been asked previously, but I haven't been able to find an example online or elsewhere.
I have very dirty data file in a text file (it may be JSON). I want to analyze the data in R, and since I am still new to the language, I want to read in the raw data and manipulate as needed from there.
How would ...