Displaying 20 results from an estimated 3000 matches similar to: "apply on function with vector as result"
2012 Sep 17
3
eval(parse(...)) only once in a function
Hi
I would like to have something like
str <- "df$JT == 12"
fun <- function(df) {
b <- eval(parse(str))
return(b)
}
but for performance "eval(parse(a))" should not be evaluated at each
function call, but should work as
fun <- function(df) {
b <- df$JT == 12
return(b)
}
Do you have an idea how I can implement this?
Thx
Christof
2012 Oct 26
2
connect points in charts
Hi
is there a automatic way that long distances between points are not
connected. I have something like
plot(x,y,type="o",...)
atx <- seq(as.Date("2009-04-01"),as.Date("2011-04-01"),"month")
axis.Date(1, at=atx,labels=format(atx, "%b\n%Y"), padj=0.5 )
but I do not want lines between points whose distance is greater than
two weeks.
thx
2012 Jul 02
2
save conditions in a list
Hi
how would you save conditions like
a = "day > 100"; b = "val < 50"; c = "year == 2012"
in a list? I like to have variables like "day", "val", "year" and a list
of conditions list(a,b,c). Then I want to check if a & b & c is true or
if a | b | c is true or similar things.
Greetings
Christof
2012 Aug 14
3
self-starter functions for y = a + b * c^x
Hi
there are some predefined self-start functions, like SSmicmen, SSbiexp,
SSasymp, SSasympOff, SSasympOrig, SSgompertz, SSflp, SSlogis, SSweibull,
Quadratic, Qubic, SSexp (nlrwr)
Btw, do you know graphic examples for this functions?
The SSexpDecay (exponential decay) for y = (y0 - plateau)*exp(-k*x) +
plateau from
2012 Jan 20
3
break an axis.POSIXct
Hi
I like to use "axis.POSIXct" to plot days from 2006 till 2008. But I
only have datas for the summer months. Is it possible to get two axis
breaks, to have not so long distances without points?
thx
Christof
2012 Oct 02
3
lattice xyplot, get current level
Hi
xyplot(y ~ x | subject) plots a separate graph of y against x for each
level of subject. But I would like to have an own function for each
level. Something like
xyplot(y ~ x | subject,
panel = function(x,y) {
panel.xyplot(x,y)
panel.curve(x,y) {
# something that dependents on the current subject
...
}
})
How I get the current
2012 Jan 09
2
RODBC vs gdata
Hi
one col in my Excel file contains many numbers. But on line 3000 and
some other lines are strings like "FG 1". "RODBS" seems to omit this
lines. "gdata" works, but is much slower.
Is this a bug of RODBC or do I apply it wrong?
Example with the same "file.xlsx"
library(RODBC); excel <- odbcConnectExcel2007("file.xlsx")
tab <-
2011 Nov 26
2
simplify source code
Hi
I would like to shorten
mod1 <- nls(ColName2 ~ ColName1, data = table, ...)
mod2 <- nls(ColName3 ~ ColName1, data = table, ...)
mod3 <- nls(ColName4 ~ ColName1, data = table, ...)
...
is there something like
cols = c(ColName2,ColName3,ColName4,...)
for i in ...
mod[i-1] <- nls(ColName[i] ~ ColName1, data = table, ...)
I am looking forward to help
Christof
2009 Apr 07
2
Puzzled by an error with apply()
I've written a function, myFunc, that works fine with myFunc(data,
...), but when I use apply() to run it with an array of data
apply(myArray, 1, myFunc, ...)
I get a strange error:
Error in match.fun(FUN) : '1' is not a function, character or symbol
which really puzzles me because '1' is meant to be the margin of the
array I want to apply over, but how come does apply()
2012 Jul 21
1
alternative to rbind for data.table
Hi
I want to add a row to a "data.table" in each round of a for loop.
"rbind" seems to be a inefficient way to implement this.
How would you do this? The "slow" solution:
library(data.table)
Rprof("test.out")
dt <- data.table()
for (i in (1:10000)) {
# algorithm that generates a list with different values,
# but same key-names, each round, for
2010 Mar 31
2
Simplifying particular piece of code
Hello, everyone
I have a piece of code that looks like this:
mrets <- merge(mrets, BMM.SR=apply(mrets, 1, MyFunc, ret="BMM.AV120",
stdev="BMM.SD120"))
mrets <- merge(mrets, GM1.SR=apply(mrets, 1, MyFunc, ret="GM1.AV120",
stdev="GM1.SD120"))
mrets <- merge(mrets, IYC.SR=apply(mrets, 1, MyFunc, ret="IYC.AV120",
2012 Sep 25
1
nlme function examples for dose-respone
Hi,
I want to fit nonlinear dose-response curves, as "fun(X,a,b,c)", for
each of our 5 trail locations. Our data basis is something like
location plot year dose response
For each location there are 4 plots as repetitions (over 3 years). So
the interactions "location*year" and "location*plot" should be random
effects.
There are some examples in "Mixed-Effects
2013 Jul 23
1
optimize integer function parameters
Hi
I have "observations" obs <- (11455, 11536, 11582, 11825, 11900, ...)
and a simulation function f(A,B,C,D,E,F), so sim <- f(A,B,C,D,E,F)
e.g. sim = c(11464, 11554, 11603, 11831, 11907, ...)
now I would like to fit A,B,C,D,E,F such that "obs" and f(A,B,C,D,E,F)
match as well as possible. A,..,F should be integers and have bounds.
How would you solve this problem
2010 Sep 23
2
dnorm
Dear R-users
Idea:
Plot a dnorm line using specific mean/sd to complete a histogram (skewed). xs:range of y-values, ys: dnorm function
Problem:
I expected to multiply the ys function with the sample size (n=250-300). I was wondering about a factor between 12'000 and 30'000 to match the size of the dnorm line with the specific histogram.
Thanks
Sibylle
hist(Biotree[Ld,]$Height2008,
2003 Aug 04
1
Novice question
Hello.
I am new R user, so this question is probably quite stupid, but for
the life of me I cannot figure out how to get predications using
multivariate linear regression analysis. Single variable predictions
work fine. I am trying the following:
-- Known y's for known x's1 and x's2
ys <- c(133890, 135000, 135790, 137300, 138130, 139100, 139900,
141120, 141890, 143230, 144000,
2011 Feb 18
1
debugger() fails if "..." in function arguments
Dear all,
I'm having a problem with debugger() in both R 2.8.0 and R 2.12.0.
Probably also versions in-between.
I don't see it logged in the bug database, but it's hard for me to
imagine that no-one else has encountered it. So my question is whether
it's a known problem with a workaround, or do I log it as a new problem?
The situation is that if I use
2005 Oct 16
2
Animated lissajous
Here's some code to make lissajous dance. I've attached a small sample
GIF.
Cheers,
Rob Steele
robsteele at yahoo dot com
plot.lissajous = function(omega.x, omega.y, delta = 0, num.thetas = 200)
{
thetas = seq(0, 2 * pi, length = num.thetas)
xs = sin(omega.x * thetas + delta)
ys = cos(omega.y * thetas)
plot(xs, ys, type = 'l', lwd = 3, ann = FALSE, axes = FALSE)
}
2004 Sep 09
4
scoping rules
Can someone help me with this simple example?
sq <- function() {
y <- x^2
y
}
myfunc <- function() {
x <- 10
sq()
}
myfunc()
executing the above in R yields:
> myfunc()
Error in sq() : Object "x" not found
I understand that R's scoping rules cause it to look for "x" in the
environment in which "sq" was defined (the global environment in
2002 Aug 06
1
re| `By reference'
David Brahm <brahm at alum.mit.edu> wrote:
>VBMorozov at lbl.gov wrote:
>> I would like to pass variables to a function in R in "by reference"...
>Just in case the ensuing discussion got too esoteric, here's one simple
answer:
>R> x <- 1:10
>R> MyFunc <- function(x, zz) assign(deparse(substitute(zz)), sum(x), 1)
>R> MyFunc(x,y)
>R>
2009 Aug 06
1
Using 'field names' of a data.frame in a function
I may be doing this wrong! but I have a function which I have simplified a lot below. I want to pass some 'field names' of a data-frame to the function for it to then do some manipulation of.
Here's my code:
#build a simple dataset
mydataset = data.frame (