That probably works in this case, but it would cause grief if another car make
had "ford" somewhere inside its name e.g. "bedford". Safer general practice is
Auto[Auto$name %in% c("ford", "toyota"),]
or similar using subset().
-pd
> On 17 Dec 2017, at 09:10 , Eric Berger <[email protected]> wrote:
>
> myAuto <- Auto[ grep("ford|toyota",Auto$name),]
>
>
>
> On Sat, Dec 16, 2017 at 10:28 PM, Bert Gunter <[email protected]>
> wrote:
>
>> I did not care to load the packages -- small reproducible examples are
>> preferable, as the posting guide suggests.
>>
>> But, if I have understood correctly:
>>
>> See, e.g. ?subset
>>
>> Alternatively, you can read up on indexing data frames in any good basic R
>> tutorial.
>>
>> Cheers,
>> Bert
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>> On Sat, Dec 16, 2017 at 11:44 AM, AbouEl-Makarim Aboueissa <
>> [email protected]> wrote:
>>
>>> Dear All:
>>>
>>> I would like to create a subset data set *with only* all Ford and all
>>> Toyota cars from the Auto data set in ISLR R Package. Thank you very
>> much
>>> in advance.
>>>
>>> Please use the following code to see how is the data look like.
>>>
>>>
>>> install.packages("ISLR")
>>> library(ISLR)
>>> data(Auto)
>>> head(Auto)
>>>
>>>
>>> with many thanks
>>> abou
>>> ______________________
>>>
>>>
>>> *AbouEl-Makarim Aboueissa, PhD*
>>>
>>> *Professor of Statistics*
>>>
>>> *Department of Mathematics and Statistics*
>>> *University of Southern Maine*
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [email protected] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/
>>> posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [email protected] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [email protected] Priv: [email protected]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.