X hits on this document

51 views

0 shares

0 downloads

0 comments

8 / 23

6

AN INTRODUCTION TO R

rank

1

1

2

2

category

sales

Banking

94.71

17.85

1264.03

15.59

626.93

6.46

647.66

3

1

255.30

2

328.54

3

194.87

name country Citigroup United States

General Electric United States Conglomerates 134.19

3 American Intl Group United

profits

assets

marketvalue

States

Insurance

76.66

...

will not be particularly helpful in gathering some initial information about the data; it is more useful to look at a description of their structure found by using the following command

R> str(Forbes2000)

'data.frame':

2000 obs. of

8 variables:

$

rank

$

name

$

country

$

category

$

sales

$

profits

: : : :

int chr

1 2 3 4 5 ... "Citigroup" "General Electric"

...

Factor

w/

61

levels

"Africa","Australia",..: 60

Factor

w/

27

levels

"Aerospace & defense",..: 2

: num

94.7 134.2 ...

: num

17.9 15.6 ...

60 60 60 56 ... 6 16 19 19 ...

$ assets

: num

1264 627 ...

$ marketvalue: num

255 329 ...

The output of the str function tells us that Forbes2000 is an object of class data.frame, the most important data structure for handling tabular statistical data in R. As expected, information about 2000 observations, i.e., companies, are stored in this object. For each observation, the following eight variables are available:

rank: the ranking of the company, name: the name of the company, country: the country the company is situated in, category: a category describing the products the company produces, sales: the amount of sales of the company in billion US dollars, profits: the profit of the company in billion US dollars, assets: the assets of the company in billion US dollars, marketvalue: the market value of the company in billion US dollars.

A similar but more detailed description is available from the help page for the Forbes2000 object:

R> help("Forbes2000") or R> ?Forbes2000

All information provided by str can be obtained by specialised functions as well and we will now have a closer look at the most important of these.

The R language is an object-oriented programming language, so every object is an instance of a class. The name of the class of an object can be determined by

R> class(Forbes2000)

Document info
Document views51
Page views51
Page last viewedWed Dec 07 20:54:57 UTC 2016
Pages23
Paragraphs684
Words5996

Comments