If I load data from file / database etc. I need to check structure of resulting object. Following examples use Test set 1:

  • “names(data)” – shows columns in data set:
    > names(data)
    [1] "first"  "last"   "age"    "city"   "gender" "state"  "dollar"
    
  • “dim(data)” – shows number of rows and columns:
    > dim(data)
    [1] 100   7
    
  • “class(data)” – shows type of data set:
    > class(data)
    [1] "data.frame"
    
  • “head(data, n=5)” – prints only 5 first rows from data set:
    > head(data, n=5)
         first       last age      city gender state   dollar
    1    Verna Fitzgerald  60   Javawge Female    RI $6150.22
    2  Garrett    Perkins  45 Amohopkih   Male    OR $8729.60
    3     Myra      Grant  34    Detema Female    OK $1746.29
    4     Ruth   Reynolds  44  Otavobeh Female    WA $4242.62
    5 Jeremiah   Jennings  26    Tatuze Female    RI $8161.88
    
  • “tail(data, n=5)” – shows only 5 last rows:
    > tail(data, n=5)
           first     last age      city gender state   dollar
    96     Flora McKinney  43 Tazramila Female    CA $8099.97
    97    Vernon    Moore  24   Mabacpi Female    CT $3622.38
    98  Isabella   Castro  64  Gulafpug Female    AK  $336.46
    99    Adrian   Guzman  36  Kuehelak Female    DE $9510.49
    100    Annie   Bowman  26   Uwewtif Female    NE $2042.16
    
  • “str(data)” – shows structure of data set – number of levels for every column + examples:
    > str(data)
    'data.frame':	100 obs. of  7 variables:
     $ first : Factor w/ 90 levels "Ada","Adeline",..: 86 37 74 83 50 44 34 6 89 42 ...
     $ last  : Factor w/ 91 levels "Adams","Alvarado",..: 26 64 32 69 46 79 23 84 28 13 ...
     $ age   : int  60 45 34 44 26 22 49 63 33 32 ...
     $ city  : Factor w/ 100 levels "Amohopkih","Azrodvut",..: 33 1 7 60 81 47 4 61 88 15 ...
     $ gender: Factor w/ 2 levels "Female","Male": 1 2 1 1 1 2 2 2 1 2 ...
     $ state : Factor w/ 41 levels "AK","AL","AR",..: 32 30 29 38 32 24 10 41 18 29 ...
     $ dollar: Factor w/ 100 levels "$10.24","$1061.38",..: 60 82 5 36 81 41 30 76 43 44 ...
    
  • “levels(data$gender)” – shows levels for specified column – see above “str” command:
    > levels(data$gender)
    [1] "Female" "Male"  
    
  • “summary(data)” – quick infos about all columns:
    > summary(data)
          first            last         age               city       gender  
     Brian   : 3   Baker     : 2   Min.   :18.00   Amohopkih: 1   Female:51  
     Clifford: 3   Black     : 2   1st Qu.:28.00   Azrodvut : 1   Male  :49  
     Blanche : 2   Fitzgerald: 2   Median :41.50   Bapmorik : 1              
     Dorothy : 2   Gregory   : 2   Mean   :40.97   Bojhuaga : 1              
     Flora   : 2   Nash      : 2   3rd Qu.:54.00   Cealire  : 1              
     Harold  : 2   Perkins   : 2   Max.   :65.00   Dajadad  : 1              
     (Other) :86   (Other)   :88                   (Other)  :94              
         state         dollar  
     NE     : 5   $10.24  : 1  
     RI     : 5   $1061.38: 1  
     MI     : 4   $1591.64: 1  
     ND     : 4   $1598.36: 1  
     OK     : 4   $1746.29: 1  
     WA     : 4   $1796.15: 1  
     (Other):74   (Other) :94  
    
  • attributes
    > attributes(data)
    $names
    [1] "first"  "last"   "age"    "city"   "gender" "state" 
    [7] "dollar"
    
    $class
    [1] "data.frame"
    
    $row.names
      [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14
     [15]  15  16  17  18  19  20  21  22  23  24  25  26  27  28
     [29]  29  30  31  32  33  34  35  36  37  38  39  40  41  42
     [43]  43  44  45  46  47  48  49  50  51  52  53  54  55  56
     [57]  57  58  59  60  61  62  63  64  65  66  67  68  69  70
     [71]  71  72  73  74  75  76  77  78  79  80  81  82  83  84
     [85]  85  86  87  88  89  90  91  92  93  94  95  96  97  98
     [99]  99 100