[R] What's data() for?

(Ted Harding) Ted.Harding at manchester.ac.uk
Fri May 14 11:35:18 CEST 2010


On 13-May-10 23:43:58, yjmha69 wrote:
> Hi there,
> 
>>library(faraway)
>>pima
> 
>     pregnant glucose diastolic triceps insulin  bmi diabetes age test
> 1          6     148        72      35       0 33.6    0.627  50    1
> 2          1      85        66      29       0 26.6    0.351  31    0
> 
>>data(pima)
>>pima
> 
>     pregnant glucose diastolic triceps insulin  bmi diabetes age test
> 1          6     148        72      35       0 33.6    0.627  50    1
> 2          1      85        66      29       0 26.6    0.351  31    0
> 
> As you can see, I can already use pima without running data(pima),
> after running data(pima), it looks the same. So what's the reason to
> use data(pima) ?
> 
> Thanks
> YJM

The difference is that data(pima) will load the dataset pima
(which can be found in the package "faraway") without the use
of library(faraway). It won't load anything else from faraway.

When you use library(faraway) you will load everything in the
package faraway, including of course the dataset pima (which is
why you see no difference, since that dataset is the same whichever
way you load it).

So with data() you put less load on your system, and also avoid
possible conflicts between what you already have in your environment
and what would be brought in when you do library(faraway).

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 14-May-10                                       Time: 10:35:15
------------------------------ XFMail ------------------------------



More information about the R-help mailing list