Displaying 20 results from an estimated 20000 matches similar to: "Passing in arguments into function"
2020 Apr 16
6
suggestion: "." in [lsv]apply()
Hi,
I would like to make a suggestion for a small syntactic modification of
FUN argument in the family of functions [lsv]apply(). The idea is to
allow one-liner expressions without typing "function(item) {...}" to
surround them. The argument to the anonymous function is simply referred
as ".". Let take an example. With this new feature, the following call
2020 Apr 16
2
suggestion: "." in [lsv]apply()
I'm sure this exists elsewhere, but, as a trade-off, could you achieve
what you want with a separate helper function F(expr) that constructs
the function you want to pass to [lsv]apply()? Something that would
allow you to write:
sapply(split(mtcars, mtcars$cyl), F(summary(lm(mpg ~ wt,.))$r.squared))
Such an F() function would apply elsewhere too.
/Henrik
On Thu, Apr 16, 2020 at 9:30 AM
2006 Sep 03
2
lm, weights and ...
> lm2 <- function(...) lm(...)
> lm2(mpg ~ wt, data=mtcars)
Call:
lm(formula = ..1, data = ..2)
Coefficients:
(Intercept) wt
37.285 -5.344
> lm2(mpg ~ wt, weights=cyl, data=mtcars)
Error in eval(expr, envir, enclos) : ..2 used in an incorrect context,
no ... to look in
Can anyone explain why this is happening? (Obviously this is a
manufactured example, but it
2007 Oct 01
4
how to plot a graph with different pch
I am trying to plot a graph but the points on the graph should be
different symbols and colors. It should represent what is in the legend.
I tried using the points command but this does not work. Is there
another command in R that would allow me to use different symbols and
colors for the points?
Thank you kindly.
data(mtcars)
plot(mtcars$wt,mtcars$mpg,xlab= "Weight(lbs/1000)",
2020 Apr 17
2
suggestion: "." in [lsv]apply()
Thanks Simon,
Now, I see better your argument.
Le 16/04/2020 ? 22:48, Simon Urbanek a ?crit?:
> ... I'm not arguing against the principle, I'm arguing about your
> particular proposal as it is inconsistent and not general.
This sounds promising for me. May be in a (new?) future, R core will
come with a correct proposal for this principle?
Meanwhile, to avoid substitute(),
2020 Apr 16
2
suggestion: "." in [lsv]apply()
Simon,
Thanks for replying. In what follows I won't try to argue (I understood
that you find this a bad idea) but I would like to make clearer some of
your point for me (and may be for others).
Le 16/04/2020 ? 16:48, Simon Urbanek a ?crit?:
> Serguei,
>> On 17/04/2020, at 2:24 AM, Sokol Serguei <sokol at insa-toulouse.fr>
>> wrote: Hi, I would like to make a
2016 Apr 14
4
Bug in by() function which works for some FUN argument and does not work for others
Dear Sirs,
I am Professor at Indira Gandhi Krishi Vishwavidyalaya, Raipur,
Chhattisgarh, India.
While taking classes, I found the *by() *function producing following error
when I use FUN=mean or median and some other functions, however,
FUN=summary works.
Given below is the output of the example I used on a built-in dataset
"mtcars", along with error message reproduced herewith:
>
2017 Mar 26
1
Documentation of model.frame() and get_all_vars()
Hi everyone,
This is about documentation for the model.frame() page. The
get_all_vars() function (added in R 2.5.0) is a great addition, but
the behavior of its '...' argument is different from that of
model.frame() with which it is documented and this creates ambiguity.
The current docs read:
\item{\dots}{further arguments such as \code{data}, \code{na.action},
\code{subset}. Any
2012 Nov 04
1
Apply same linear model to subset of dataframe
I have applied the same linear model to several different subsets of a
dataset. I recently read that in R, code should never be repeated. I feel my
code as it currently stands has a lot of repetition, which could be
condensed into fewer lines. I will use the mtcars dataset to replicate what
I have done. My question is: how can I use fewer lines of code (for example
using a for loop, a function or
2016 Apr 14
0
Bug in by() function which works for some FUN argument and does not work for others
I think you are not using the best function for what your intentions are.
Try:
> by(data=mtcars, INDICES=list(as.factor(mtcars$am)), FUN=colMeans)
: 0
mpg cyl disp hp drat wt
qsec vs
17.1473684 6.9473684 290.3789474 160.2631579 3.2863158 3.7688947
18.1831579 0.3684211
am gear carb
0.0000000
2017 Jun 20
3
error while creating a simple graph
Dear All,
I am learning R so it's a very simple problem but I do not understand while
I am not able to generate a graph from two vectors.
when I type this code, it generates a very nice graph.
pdf("mygraph.pdf")
> attach(mtcars)
> plot(wt,mpg)
> abline(lm(mpg~wt))
> title("Regreesion of mpg")
> detach(mtcars)
> dev.off()
But I am trying to create a
2009 Aug 16
2
bootstrapped correlation confint lower than -1 ?
Dear R users,
Does the results below make any sense? Can the the interval of the
correlation coefficient be between *-1.0185* and -0.8265 at 95%
confidence level?
Liviu
> library(boot)
> data(mtcars)
> with(mtcars, cor.test(mpg, wt, met="spearman"))
Spearman's rank correlation rho
data: mpg and wt
S = 10292, p-value = 1.488e-11
alternative hypothesis: true rho is not
2016 Apr 15
4
Bug in by() function which works for some FUN argument and does not work for others
Dear All,
Thanks for your help. However, I would like to draw your attention to the
following:
Actually, I was replicating the Example 2.3, using the dataset
"brainsize.txt" given in Section 2.3.3 ("Summarize by group") at page 55,
of a famous book "R by Example" written by "Jim Albert and Maria Rizzo"
published in Springers (2012) in a Use R! Series. The
2003 Jul 22
1
Conditional Statements for Graphing
Dear List
I have math test scores for male and female students where gender is a dummy code (female =1). I also have a variety of other demographic variables.
However to begin, I want to create a very simple stripchart where female math scores are a blue circle and male scores are a red triangle.
I am having difficulty using conditional statements to accomplish this.
Thank you.
------
2007 Apr 16
2
Plotting data with a fitted curve
Suppose you have a vector of data in x and response values in y. How
do you plot together both the points (x,y) and the curve that results
from the fitted model, if the model is not y ~ x, but a higher order
polynomial, e.g. y~poly(x,2)? (In other words, abline doesn't work
for this case.)
Thanks,
--Paul
--
Paul Lynch
Aquilent, Inc.
National Library of Medicine (Contractor)
2013 Apr 12
3
Why copying columns of a data.frame becomes numeric?
Dear list,
I want the 1st, 2nd, 5th, and 6th columns of mtcars. After copying them,
the columns become numeric class rather than data frame.
But, when I copy rows, they data frame retains its class. Why is this? I
don't see why copying rows vs columns is so different.
> class(mtcars)
[1] "data.frame"
> head(mtcars)
mpg cyl disp hp drat wt qsec vs
2017 Aug 16
1
Bias-corrected percentile confidence intervals
Hi folks,
I'm trying to estimate bias-corrected percentile (BCP) confidence
intervals on a vector from a simple for loop used for resampling. I am
attempting to follow steps in Manly, B. 1998. Randomization, bootstrap
and monte carlo methods in biology. 2nd edition., p. 48. PDF of the
approach/steps should be available here:
https://wyocoopunit.box.com/s/9vm4vgmbx5h7um809bvg6u7wr392v6i9
If
2020 Apr 20
1
suggestion: "." in [lsv]apply()
Le 19/04/2020 ? 20:46, Gabor Grothendieck a ?crit?:
> You can get pretty close to that already using fn$ in the gsubfn package:
>> library(gsubfn) fn$sapply(split(mtcars, mtcars$cyl), x ~
>> summary(lm(mpg ~ wt, x))$r.squared)
> 4 6 8 0.5086326 0.4645102 0.4229655
Right, I thought about similar syntax but this implementation has
similar flaws pointed by Simon, i.e. it reduces
2012 Oct 29
1
change lm log(x) to glm poisson
Hello list,
I am running a regression using
lm(Y~A+B+log(C)+log(D))
Now, I would like to test if glm can produce similar results.
So the code was revised as
glm(Y~A+B+C+D, family=poisson) (code 1)
However, I found some example using glm for lm.
It suggests that the code should be revised like
glm(Y~A+B+log(C)+log(D), family=poisson) (code 2)
Please kindly advise which code is correct.
2024 Sep 22
2
store list objects in data.table
Thanks everyone for their responses.
My data is organized in a data.table.? My goal is to perform analyses
according to some groups.? The results of analysis are objects.? If
these objects could be stored as elements of a data.table, this would
help downstream summarizing of results.
Let me try another example.
carsdt <- setDT(copy(mtcars))
carsdt[, unique(cyl) |> length()]
#[1] 3