Displaying 20 results from an estimated 335 matches for "mtcars".
2007 Oct 01
4
how to plot a graph with different pch
...ut 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)", ylab="Miles per
Gallon")
mtcars$wt.cyl<-mtcars$wt[mtcars$cyl]
mtcars$mpg.cyl<-mtcars$mpg[mtcars$cyl]
points(mtcars$wt.cyl, mtcars$mpg.cyl, pch = 17, col = "red")
title("Motor Trend Data")
text(2...
2011 Dec 13
1
How to add points to two plots parallelly ?
I am looking for ways to add points to three different plots in parallel.
I generate three scatter plots and name them as s3d1, s3d2 and s3d3
s3d1<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
s3d2<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
s3d3<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
If I try to add points to s3d1,
s3d1$points3d(mtcars[,3],mtcars...
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)
m...
2020 Apr 16
6
suggestion: "." in [lsv]apply()
...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
sapply(split(mtcars, mtcars$cyl), function(d) summary(lm(mpg ~ wt,
d))$r.squared)
#??????? 4???????? 6???????? 8
#0.5086326 0.4645102 0.4229655
could be rewritten as
sapply(split(mtcars, mtcars$cyl), summary(lm(mpg ~ wt, .))$r.squared)
"Not a big saving in typing" you can say but multiplied by the numbe...
2017 Aug 16
1
Bias-corrected percentile confidence intervals
...ysis I am working on (the boot function became quite
challenging, for me, for a few reasons).
I cannot figure out where I'm going wrong but the estimates from my
attempt at the BCP CI are different enough from other methods that I
assume I'm doing something wrong.
require(boot)
data("mtcars")
# 1) Bootstrap 95% CI for R-Squared via boot::boot
# statmethods.net/advstats/bootstrapping.html
# Function for boot
rsq <- function(formula, data, indices) {
d <- data[indices,]
fit <- lm(formula, data=d)
return(summary(fit)$r.square)
}
# bootstrapping with 1000 replicatio...
2012 Mar 15
2
Ggplot barchart drops factor levels: how to show them with zero counts?
Hello,
When plotting a barchart with ggplot it drops the levels of the factor for
which no counts are available.
For example:
library(ggplot)
mtcars$cyl<-factor(mtcars$cyl)
ggplot(mtcars[!mtcars$cyl==4,], aes(cyl))+geom_bar()
levels(mtcars[!mtcars$cyl==4,])
This shows my problem. Because no counts are available for factorlevel '4',
the label 4 dissapears from the plot. However, I would still like it to show
up, but without a bar (ze...
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 Michael Mahoney
<mike.mahoney.218 at gmail.com> wrote:
>
> This syntax is already implemented in the {purrr} package, more or
> less -- you n...
2010 Aug 04
3
retrieve name of an object?
Dear all
Is there an easier way to retrieve the name of an object? For example,
> tmp <- 1:10
> as.character(quote(tmp))
[1] "tmp"
> as.character(quote(mtcars$cyl))
[1] "$" "mtcars" "cyl"
> as.character(quote(mtcars$cyl))[3]
[1] "cyl"
The last call more than anything seems a hack. Is there a better way?
Thank you
Liviu
2011 Jun 21
5
omitting columns from a data frame
Dear R People:
I have a data frame, xm1, which has 12 rows and 4 columns.
If I put is xm1[,-4], I get all rows, and columns 1 - 3, which is as
it should be.
Now, is there a way to use the names of the columns to omit them, please?
Thanks so much in advance!
Sincerely,
Erin
--
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
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 wron...
2017 Aug 29
2
DBI::dbWriteTable syntax error apparently from quotes
...sfully 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: <SQL> 'CREATE TABLE "mtcars" (
"row_names" varchar(255),
"mpg" FLOAT,
"cyl" FLOAT,
"disp" FLOAT,
"hp" FLOAT,
"drat" FLOAT,
"wt&q...
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 1st
principal component
mtcars$PC2 <- .PC$scores[,2] # extract un-rota...
2009 Dec 16
0
Read dataset in R language
Hello.
This is to get you started with data.frames, next time please
- read the posting guide
- see the documentation, especially the builtin "R data import/export"
manual form the help menu
## begin R examples, paste into console ##
data(mtcars) # builtin database
class(mtcars) # what it is
mtcars # print it out...
head(mtcars) # ...better: see first rows
fm <- mpg~hp+wt
summary(lm(fm, data=mtcars)) # my favourite regression: see ?mtcars
save(mtcars, file="mtcars.rda") # save as R binary in current working
directory
load(file...
2004 Jan 22
1
stem plot problem with the mtcars data (PR#6453)
Full_Name: Liming Liang
Version: 1.8.1
OS: windows2000 professional
Submission from: (NULL) (67.172.81.139)
I was looking at the variable 'mpg' of the data file 'mtcars' and make a stem
plot, the following is the commend I entered. The stem plot shows the largest
observation is 32.9 but actually in the data the largest observation is 33.9,
here might be a problem.
> data(mtcars)
> stem(mtcars$mpg)
The decimal point is at the |
10 | 44
12 | 3
1...
2013 May 17
2
Selecting A List of Columns
...lt;-colnames(x)
to.keep<-all.cols[1:2]
Kept<-subset(x,select=to.keep)
Kept
However, if I want to select some columns based on a selection of the most
important variables from a random forest then I find myself stuck. The
example below demonstrates the problem.
library(randomForest)
data(mtcars)
mtcars.rf <- randomForest(mpg ~ ., data=mtcars,importance=TRUE)
Importance<-data.frame(mtcars.rf$importance)
Importance
MSEImportance<-head(Importance[order(Importance$X.IncMSE,
decreasing=TRUE),],3)
MSEVars<-row.names(MSEImportance)
MSEVars<-data.frame(MSEVars,stringsAsFactors =...
2017 Jun 01
3
odfWeave - A loop of the "same" data
Before I go and do this another way - can I check if anyone has a way of looping through data in odfWeave (or possibly sweave) to do a repeating analysis on subsets of data?
For simplicity lets use mtcars dataset in R to explain. Dataset looks like this:
> mtcars
mpg cyl disp hp drat wt ...
Mazda RX4 21.0 6 160 110 3.90 2.62 ...
Mazda RX4 Wag 21.0 6 160 110 3.90 2.88 ...
Datsun 710 22.8 4 108 93 3.85 2.32 ...
............
Say I wanted to have a...
2020 Apr 17
2
suggestion: "." in [lsv]apply()
...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 sapply(split(mtcars,
>>>> mtcars$cyl), function(d) summary(lm(mpg ~ wt, d))$r.squared) # 4 6
>>>> 8 #0.5086326 0.4645102 0.4229655 could be rewritten as
>>>> sapply(split(mtcars, mtcars$cyl), summary(lm(mpg ~ wt,
>>>> .))$r.squared) "Not a big saving in typing&q...
2012 Jul 02
3
residuals from lm
Hi,
I was playing around with something else and I noticed this matrix code for
residuals in a linear model doesn't say what lm() says. Please tell me if I
am completely misguided here.
data(mtcars)
Y <- as.matrix(mtcars[,1])
X <- as.matrix(mtcars[,c(2:11)])
# shouldnt this:
H <- X %*% solve(t(X) %*% X) %*% t(X)
(diag(dim(H)[1]) - H) %*% Y
# be equal to this:
residuals(lm(Y~X))
# ???
# thanks
--
View this message in context: http://r.789695.n4.nabble.com/residuals-from-lm...
2020 Apr 16
2
suggestion: "." in [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 sapply(split(mtcars,
>> mtcars$cyl), function(d) summary(lm(mpg ~ wt, d))$r.squared) # 4 6 8
>> #0.5086326 0.4645102 0.4229655 could be rewritten as
>> sapply(split(mtcars, mtcars$cyl), summary(lm(mpg ~ wt, .))$r.squared)
>> "Not a big saving in typing" you can say but multiplied...
2016 Apr 14
4
Bug in by() function which works for some FUN argument and does not work for others
...a 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:
> by(data=mtcars, INDICES=list(mtcars$am), FUN=mean)
: 0
[1] NA
------------------------------------------------------------
: 1
[1] NA
Warning messages:
1: In mean.default(data[x, , drop = FALSE], ...) :
argument is not numeric or logical:...