In matlab there is a way to find the values in one vector but not in the other.
for example:
x <- c(1,2,3,4)
y <- c(2,3,4)
is there any function that would tell me that the value in x that's not in y is 1?
...
the function I am writing specifies the behaviour of a physical switch: it should be turned ON if a value goes above an upper threshold and can go again OFF if it goes under the lower threshold. a similar logic would describe a normal thermostat in a household oven. obviously I want it to work on vectors, that's the whole point!
so if...
Take for example the following ftable
height <- c(rep('short', 7), rep('tall', 3))
girth <- c(rep('narrow', 4), rep('wide', 6))
measurement <- rnorm(10)
foo <- data.frame(height=height, girth=girth, measurement=measurement)
ftable.result <- ftable(foo$height, foo$girth)
I'd like to convert the above ftable.result into a matrix with ro...
I'd like to read the contents of a URL (e.q., http://www.haaretz.com/) in R. I am wondering how I can do it
...
I've used RODBC for some time to import Excel spreadsheets with mostly good results. However I have had no luck writing to an Excel spreadsheet. Also are there favorable differences using the xlsx format with Excel2007?
...
Is there a way of overlaying a mathematical function on top of data using ggplot?
## add ggplot2
library(ggplot2)
# function
eq = function(x){x*x}
# Data
x = (1:50)
y = eq(x)
# Make plot object
p = qplot(
x, y,
xlab = "X-axis",
ylab =...
I have a situation in which I have to give a formula as input to the nls() function.
I have data which is between time and variance. For example:
Time Variance
1 0.15
2 0.23
3 0.67
4 0.85
Now I am using the formula Vt = ((1-e^kt)/kt)) (q^2)/2k, where Vt is the variance at time t. I have the two variables (k,q) in the above ...
I have a table where there are "NA"s littered all over the place in one column in particular. I want to replace every instance of "NA" with something else -- say, the number 1.
How should I do that?
...
I am trying to reshape a data frame in R and it seems to have problems using the recommended ways of doing so. The data frame has the following structure:
ID DATE1 DATE2 VALTYPE VALUE
'abcd1233' 2009-11-12 2009-12-23 'TYPE1' 123.45
...
VALTYPE is a strin...
a function I wrote extracts timestamps from a XML document. Timestamps are coupled to events, which are repeated elements of the series element.
series elements have a variable amount of events, so my function returns a data.frame (if the series have the same length). in general it returns a more generic list and I want it to work wit...
We are currently using R to automatically generate various kinds of boxplots. The problem we have is that the length our labels varies considerably between different plots and classes in one plot.
Is there a way to automatically adjust the plot so that all the labels will fit it nicely? Specifying a worst case mar isn't feasible because...
Hi all, I'm reading a text file like this in R 2.10.0
248585_at 250887_at 245638_s_at AFFX-BioC-5_at
248585_at 250887_at 264488_s_at 245638_s_at AFFX-BioC-5_at AFFX-BioC-3_at AFFX-BioDn-5_at
248585_at 250887_at
Using the command
clusters<-read.delim("test",sep="\t",fill=TRUE,header=FALSE)
Now, I must pass every row in this ...
I have a df and I want to do multiple transform on it with plyr:
idplot / idtree / species / condition / dbh_cm / h_m / hblc_m
CalcG <- function (df) transform(df, g_m2 = pi * (dbh_cm^2)/40000)
CalcHD <- function (df) transform(df, hd = h_m / dbh_cm)
...
Can be done in one function?
Many thanks.
...
I have a vector: c(1,2,3)
Calling print() on this value gives "[1] 1 2 3"
Is there a function that takes a vector and gives the string "c(1,2,3)"?
...
I'm trying to read a text file with different row lengths:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
To overcome this problem, I'm using the argument fill=TRUE in read.table, so:
data<-read.table("test",sep="\t",fill=TRUE)
Unfortunately, to assess the maximum row length, read.table reads ...
I have multiple sets of xy pairs that I want to plot. I want each set of xy pairs to be connected by a line. In other words the goal is to have multiple experimental instances each approximated by a line plotted on one plot. Also how would I colour the lines differently?
The plot function does what I want, but takes on one set of xy ...
I'm working with a large data frame, and have run up against RAM limits. At this point, I probably need to work with a serialized version on the disk. There are a few packages to support out-of-memory operations, but I'm not sure which one will suit my needs. I'd prefer to keep everything in data frames, so the ff package looks encouragi...
Hi
I have a dataframe that I want to reshape; my reshape code:
matchedlong <- reshape(matched, direction = 'long',
varying = c(29:33, 36:3943),
v.names = c("Math34", "TFCIn"),
times = 2006:2009, idvar = "schoolnum")
in "matched" columns 36 to 39 are logical (TRUE FAL...
so I decided I would put my few R functions into a package and I'm reading/learning Writing R Extension.
it obviously complains about an amount of things I'm not doing right.
after enough googling, I'm firing a few questions here, this one is about testing style: I am using RUnit and I like having tests as close possible to the code be...
this sounds like a silly problem: I'm putting my R code into a package and R CMD check src complains about the .Rd~ backup files being produced by Emacs.
* checking package subdirectories ... WARNING
Subdirectory 'man' contains invalid file names:
read.PI.Rd~ write.PI.Rd~
the documentation says: »In addition [...] files [...] wit...