Displaying 20 results from an estimated 2000 matches similar to: "Apply same linear model to subset of dataframe"
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
2020 Oct 18
1
Resultado de la consola como un tibble
Hola,
Bueno, puedes hacer el cálculo de una forma mucho más compacta y rápida.
Esta forma es especialmente recomendable cuando tienes muchas columnas y
muchas filas.
> library(data.table)
> myDT <- as.data.table(mtcars)
> myDTlong <- melt(myDT, measure.vars=1:ncol(myDT))
> myDTlong[ , list(p_value = shapiro.test(value)$p.value, v_stat =
shapiro.test(value)$statistic) , by
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
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:
>
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
2016 Apr 15
0
Bug in by() function which works for some FUN argument and does not work for others
> On Apr 15, 2016, at 1:16 AM, Akhilesh Singh <akhileshsingh.igkv at gmail.com> wrote:
>
> 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
2016 Apr 16
2
Bug in by() function which works for some FUN argument and does not work for others
Dear All,
I have got your core message, that it is my responsibility to determine
whether any particular function in my version of R satisfies the language
requirements at the time of your use. Jim Albert and Maria Rizzo must have
used their code, which was permitted in the R-code of their time (2012).
Therefore, I have now modified my R-code, as per R-3..2.4 version,
according to my requirement
2017 Aug 29
2
DBI::dbWriteTable syntax error apparently from quotes
I have been successfully using RODBC for a long time (years) to connect to
MS SQL Server from R.
This week I wanted to try using odbc but I am seeing some problems which
may be related to how I set up my driver and/or connection.
The dbWriteTable manual page gives as an example command:
dbWriteTable( pDB$con, "mtcars", mtcars[1:5,])
When I try this I get the following error
Error:
2016 Apr 17
0
Bug in by() function which works for some FUN argument and does not work for others
> On Apr 16, 2016, at 2:03 AM, Akhilesh Singh <akhileshsingh.igkv at gmail.com> wrote:
>
> Dear All,
>
> I have got your core message, that it is my responsibility to determine whether any particular function in my version of R satisfies the language requirements at the time of your use. Jim Albert and Maria Rizzo must have used their code, which was permitted in the R-code
2017 Aug 29
0
DBI::dbWriteTable syntax error apparently from quotes
Double quotes are not legal SQL syntax. Use single quotes.
--
Sent from my phone. Please excuse my brevity.
On August 29, 2017 2:21:44 AM PDT, Eric Berger <ericjberger at gmail.com> wrote:
>I have been successfully using RODBC for a long time (years) to connect
>to
>MS SQL Server from R.
>This week I wanted to try using odbc but I am seeing some problems
>which
>may be
2020 Oct 18
2
Resultado de la consola como un tibble
Buen día
estimados
Estoy tratando de hacer un tibble con los resultados de un apply que se
muestran en la consola que me da R, no estoy seguro si eso se pueda hacer,
pero me gustaría organizar los resultados de esa manera.
mi código es:
data("mtcars")
Mtcars_matriz <- as.matrix(mtcars)
apply(Mtcars_matriz, MARGIN =2, FUN = shapiro.test)
DF2 <- tibble(Variable = NA, W = NA, Pvalue =
2007 May 12
2
Implicit vs explicit printing and the call stack
Hi everyone,
I've run into a bit of strange problem with implicit vs explicit
printing and the call stack. I've included an example at the bottom of
this email. The basic problem is that I have an S3 object with a
print method. When the object is implicitly printed (ie. typed
directly into the console) the function arguments in the call stack
are exploded out to their actual values,
2013 Apr 16
2
efficiently diff two data frames
Dear all,
What is the quickest and most efficient way to diff two data frames,
so as to obtain a vector of indices (or logical) for rows/columns that
differ in the two data frames? For example,
> Xe <- head(mtcars)
> Xf <- head(mtcars)
> Xf[2:4,3:5] <- 55
> all.equal(Xe, Xf)
[1] "Component 3: Mean relative difference: 0.6863118"
[2] "Component 4: Mean relative
2010 Nov 30
3
pca analysis: extract rotated scores?
Dear all
I'm unable to find an example of extracting the rotated scores of a
principal components analysis. I can do this easily for the un-rotated
version.
data(mtcars)
.PC <- princomp(~am+carb+cyl+disp+drat+gear+hp+mpg, cor=TRUE, data=mtcars)
unclass(loadings(.PC)) # component loadings
summary(.PC) # proportions of variance
mtcars$PC1 <- .PC$scores[,1] # extract un-rotated scores of
2009 Apr 27
0
VIF's in R using BIGLM
Dear R-help
This is a follow-up to my previous post here:
http://groups.google.com/group/r-help-archive/browse_thread/thread/d9b6f87ce06a9fb7/e9be30a4688f239c?lnk=gst&q=dobomode#e9be30a4688f239c
I am working on developing an open-source automated system for running
batch-regressions on very large datasets. In my previous post, I posed
the question of obtaining VIF's from the output of
2012 Nov 19
2
lattice: defining grouping variable only for the upper/lower panel with splom
Using the mtcars dataset, how to define the grouping variable to be valid
only for the upper or lower panel?
The following doesn't work:
# Code start
splom(~data.frame(mpg, disp, hp, drat, wt, qsec),
data=mtcars, pscales=0,
auto.key=list(columns=3),
upper.panel = function(...){
panel.grid(...)
panel.xyplot(groups=cyl,...)
}
)
# Code end
--
View
2012 Feb 17
1
Dataframe subset - why doesn't this work?
data(mtcars)
mtcars[rownames(mtcars)!="Valiant",] # fails
mtcars[list(rownames(mtcars))!="Valiant",] # runs but I am not getting the expected result
With the latter statement, I expected all rows except the one where the name is "Valiant".
I must have got something simple wrong; what is it?
Thanks.
[[alternative HTML version deleted]]
2013 Apr 17
2
remove higher order interaction terms
Dear all,
Consider the model below:
> x <- lm(mpg ~ cyl * disp * hp * drat, mtcars)
> summary(x)
Call:
lm(formula = mpg ~ cyl * disp * hp * drat, data = mtcars)
Residuals:
Min 1Q Median 3Q Max
-3.5725 -0.6603 0.0108 1.1017 2.6956
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.070e+03 3.856e+02 2.776 0.01350 *
cyl
2018 May 10
4
the first name of the first column
Dear all;
I need to run heatmap. Because my first column in my data is alphanumeric,
I can not run as.matrix(scale(my_data)). So I need to make my data readable
as in data(mtcars). In *mtcars *data the first column is alphanumeric and
has no name.
Thanks,
Greg
[[alternative HTML version deleted]]
2020 Oct 18
0
Resultado de la consola como un tibble
Hola,
No hace falta (en este caso) capturarlo de la consola.
El resultado de la función apply se puede capturar y procesar.
> data("mtcars")
> # Mtcars_matriz <- as.matrix(mtcars)
> res_out <- apply(mtcars, MARGIN =2, FUN = shapiro.test)
>
>
> res_df <- as.data.frame(unlist(res_out))
> res_df$vars <- rownames(res_df)
> rownames(res_df) <- NULL