Single Sample

############Single Samples###########
##The Normal Distribution

worms<- span=""> read.table("worms.txt",header=T,row.names=1)
names(worms)
## [1] "Area"         "Slope"        "Vegetation"   "Soil.pH"     
## [5] "Damp"         "Worm.density"
attach(worms)
worms
##                   Area Slope Vegetation Soil.pH  Damp Worm.density
## Nashs.Field        3.6    11  Grassland     4.1 FALSE            4
## Silwood.Bottom     5.1     2     Arable     5.2 FALSE            7
## Nursery.Field      2.8     3  Grassland     4.3 FALSE            2
## Rush.Meadow        2.4     5     Meadow     4.9  TRUE            5
## Gunness.Thicket    3.8     0      Scrub     4.2 FALSE            6
## Oak.Mead           3.1     2  Grassland     3.9 FALSE            2
## Church.Field       3.5     3  Grassland     4.2 FALSE            3
## Ashurst            2.1     0     Arable     4.8 FALSE            4
## The.Orchard        1.9     0    Orchard     5.7 FALSE            9
## Rookery.Slope      1.5     4  Grassland     5.0  TRUE            7
## Garden.Wood        2.9    10      Scrub     5.2 FALSE            8
## North.Gravel       3.3     1  Grassland     4.1 FALSE            1
## South.Gravel       3.7     2  Grassland     4.0 FALSE            2
## Observatory.Ridge  1.8     6  Grassland     3.8 FALSE            0
## Pond.Field         4.1     0     Meadow     5.0  TRUE            6
## Water.Meadow       3.9     0     Meadow     4.9  TRUE            8
## Cheapside          2.2     8      Scrub     4.7  TRUE            4
## Pound.Hill         4.4     2     Arable     4.5 FALSE            5
## Gravel.Pit         2.9     1  Grassland     3.5 FALSE            1
## Farm.Wood          0.8    10      Scrub     5.1  TRUE            3
worms[,1:3]
##                   Area Slope Vegetation
## Nashs.Field        3.6    11  Grassland
## Silwood.Bottom     5.1     2     Arable
## Nursery.Field      2.8     3  Grassland
## Rush.Meadow        2.4     5     Meadow
## Gunness.Thicket    3.8     0      Scrub
## Oak.Mead           3.1     2  Grassland
## Church.Field       3.5     3  Grassland
## Ashurst            2.1     0     Arable
## The.Orchard        1.9     0    Orchard
## Rookery.Slope      1.5     4  Grassland
## Garden.Wood        2.9    10      Scrub
## North.Gravel       3.3     1  Grassland
## South.Gravel       3.7     2  Grassland
## Observatory.Ridge  1.8     6  Grassland
## Pond.Field         4.1     0     Meadow
## Water.Meadow       3.9     0     Meadow
## Cheapside          2.2     8      Scrub
## Pound.Hill         4.4     2     Arable
## Gravel.Pit         2.9     1  Grassland
## Farm.Wood          0.8    10      Scrub
worms[5:15,]
##                   Area Slope Vegetation Soil.pH  Damp Worm.density
## Gunness.Thicket    3.8     0      Scrub     4.2 FALSE            6
## Oak.Mead           3.1     2  Grassland     3.9 FALSE            2
## Church.Field       3.5     3  Grassland     4.2 FALSE            3
## Ashurst            2.1     0     Arable     4.8 FALSE            4
## The.Orchard        1.9     0    Orchard     5.7 FALSE            9
## Rookery.Slope      1.5     4  Grassland     5.0  TRUE            7
## Garden.Wood        2.9    10      Scrub     5.2 FALSE            8
## North.Gravel       3.3     1  Grassland     4.1 FALSE            1
## South.Gravel       3.7     2  Grassland     4.0 FALSE            2
## Observatory.Ridge  1.8     6  Grassland     3.8 FALSE            0
## Pond.Field         4.1     0     Meadow     5.0  TRUE            6
#select only those rows which have Area > 3 and Slope < 3
worms[Area>3 & Slope<3, ]
##                 Area Slope Vegetation Soil.pH  Damp Worm.density
## Silwood.Bottom   5.1     2     Arable     5.2 FALSE            7
## Gunness.Thicket  3.8     0      Scrub     4.2 FALSE            6
## Oak.Mead         3.1     2  Grassland     3.9 FALSE            2
## North.Gravel     3.3     1  Grassland     4.1 FALSE            1
## South.Gravel     3.7     2  Grassland     4.0 FALSE            2
## Pond.Field       4.1     0     Meadow     5.0  TRUE            6
## Water.Meadow     3.9     0     Meadow     4.9  TRUE            8
## Pound.Hill       4.4     2     Arable     4.5 FALSE            5
#whole dataframe sorted by Area smaller numerical variable first
worms[order(Area),] #by rows
##                   Area Slope Vegetation Soil.pH  Damp Worm.density
## Farm.Wood          0.8    10      Scrub     5.1  TRUE            3
## Rookery.Slope      1.5     4  Grassland     5.0  TRUE            7
## Observatory.Ridge  1.8     6  Grassland     3.8 FALSE            0
## The.Orchard        1.9     0    Orchard     5.7 FALSE            9
## Ashurst            2.1     0     Arable     4.8 FALSE            4
## Cheapside          2.2     8      Scrub     4.7  TRUE            4
## Rush.Meadow        2.4     5     Meadow     4.9  TRUE            5
## Nursery.Field      2.8     3  Grassland     4.3 FALSE            2
## Garden.Wood        2.9    10      Scrub     5.2 FALSE            8
## Gravel.Pit         2.9     1  Grassland     3.5 FALSE            1
## Oak.Mead           3.1     2  Grassland     3.9 FALSE            2
## North.Gravel       3.3     1  Grassland     4.1 FALSE            1
## Church.Field       3.5     3  Grassland     4.2 FALSE            3
## Nashs.Field        3.6    11  Grassland     4.1 FALSE            4
## South.Gravel       3.7     2  Grassland     4.0 FALSE            2
## Gunness.Thicket    3.8     0      Scrub     4.2 FALSE            6
## Water.Meadow       3.9     0     Meadow     4.9  TRUE            8
## Pond.Field         4.1     0     Meadow     5.0  TRUE            6
## Pound.Hill         4.4     2     Arable     4.5 FALSE            5
## Silwood.Bottom     5.1     2     Arable     5.2 FALSE            7
worms[order(worms[,1]),1:6] #same 7as above
##                   Area Slope Vegetation Soil.pH  Damp Worm.density
## Farm.Wood          0.8    10      Scrub     5.1  TRUE            3
## Rookery.Slope      1.5     4  Grassland     5.0  TRUE            7
## Observatory.Ridge  1.8     6  Grassland     3.8 FALSE            0
## The.Orchard        1.9     0    Orchard     5.7 FALSE            9
## Ashurst            2.1     0     Arable     4.8 FALSE            4
## Cheapside          2.2     8      Scrub     4.7  TRUE            4
## Rush.Meadow        2.4     5     Meadow     4.9  TRUE            5
## Nursery.Field      2.8     3  Grassland     4.3 FALSE            2
## Garden.Wood        2.9    10      Scrub     5.2 FALSE            8
## Gravel.Pit         2.9     1  Grassland     3.5 FALSE            1
## Oak.Mead           3.1     2  Grassland     3.9 FALSE            2
## North.Gravel       3.3     1  Grassland     4.1 FALSE            1
## Church.Field       3.5     3  Grassland     4.2 FALSE            3
## Nashs.Field        3.6    11  Grassland     4.1 FALSE            4
## South.Gravel       3.7     2  Grassland     4.0 FALSE            2
## Gunness.Thicket    3.8     0      Scrub     4.2 FALSE            6
## Water.Meadow       3.9     0     Meadow     4.9  TRUE            8
## Pond.Field         4.1     0     Meadow     5.0  TRUE            6
## Pound.Hill         4.4     2     Arable     4.5 FALSE            5
## Silwood.Bottom     5.1     2     Arable     5.2 FALSE            7
worms[order(Area),c(2,3,5)]#column numbers 2, 3, 5 and 7:
##                   Slope Vegetation  Damp
## Farm.Wood            10      Scrub  TRUE
## Rookery.Slope         4  Grassland  TRUE
## Observatory.Ridge     6  Grassland FALSE
## The.Orchard           0    Orchard FALSE
## Ashurst               0     Arable FALSE
## Cheapside             8      Scrub  TRUE
## Rush.Meadow           5     Meadow  TRUE
## Nursery.Field         3  Grassland FALSE
## Garden.Wood          10      Scrub FALSE
## Gravel.Pit            1  Grassland FALSE
## Oak.Mead              2  Grassland FALSE
## North.Gravel          1  Grassland FALSE
## Church.Field          3  Grassland FALSE
## Nashs.Field          11  Grassland FALSE
## South.Gravel          2  Grassland FALSE
## Gunness.Thicket       0      Scrub FALSE
## Water.Meadow          0     Meadow  TRUE
## Pond.Field            0     Meadow  TRUE
## Pound.Hill            2     Arable FALSE
## Silwood.Bottom        2     Arable FALSE
worms[rev(order(worms[,5])),c(5,6)] 
##                    Damp Worm.density
## Farm.Wood          TRUE            3
## Cheapside          TRUE            4
## Water.Meadow       TRUE            8
## Pond.Field         TRUE            6
## Rookery.Slope      TRUE            7
## Rush.Meadow        TRUE            5
## Gravel.Pit        FALSE            1
## Pound.Hill        FALSE            5
## Observatory.Ridge FALSE            0
## South.Gravel      FALSE            2
## North.Gravel      FALSE            1
## Garden.Wood       FALSE            8
## The.Orchard       FALSE            9
## Ashurst           FALSE            4
## Church.Field      FALSE            3
## Oak.Mead          FALSE            2
## Gunness.Thicket   FALSE            6
## Nursery.Field     FALSE            2
## Silwood.Bottom    FALSE            7
## Nashs.Field       FALSE            4
summary(worms)
##       Area           Slope           Vegetation    Soil.pH     
##  Min.   :0.800   Min.   : 0.00   Arable   :3    Min.   :3.500  
##  1st Qu.:2.175   1st Qu.: 0.75   Grassland:9    1st Qu.:4.100  
##  Median :3.000   Median : 2.00   Meadow   :3    Median :4.600  
##  Mean   :2.990   Mean   : 3.50   Orchard  :1    Mean   :4.555  
##  3rd Qu.:3.725   3rd Qu.: 5.25   Scrub    :4    3rd Qu.:5.000  
##  Max.   :5.100   Max.   :11.00                  Max.   :5.700  
##     Damp          Worm.density 
##  Mode :logical   Min.   :0.00  
##  FALSE:14        1st Qu.:2.00  
##  TRUE :6         Median :4.00  
##  NA's :0         Mean   :4.35  
##                  3rd Qu.:6.25  
##                  Max.   :9.00
with(worms,tapply(Worm.density,Vegetation,mean))
##    Arable Grassland    Meadow   Orchard     Scrub 
##  5.333333  2.444444  6.333333  9.000000  5.250000
help(with)
## starting httpd help server ... done
aggregate(worms[,c(2,4,6)],list(Vegetation),mean)
##     Group.1    Slope  Soil.pH Worm.density
## 1    Arable 1.333333 4.833333     5.333333
## 2 Grassland 3.666667 4.100000     2.444444
## 3    Meadow 1.666667 4.933333     6.333333
## 4   Orchard 0.000000 5.700000     9.000000
## 5     Scrub 7.000000 4.800000     5.250000
help(aggregate)
aggregate(worms[,c(2,4,6)],list(Moisture=Damp,Community=Vegetation),mean)
##   Moisture Community    Slope  Soil.pH Worm.density
## 1    FALSE    Arable 1.333333 4.833333     5.333333
## 2    FALSE Grassland 3.625000 3.987500     1.875000
## 3     TRUE Grassland 4.000000 5.000000     7.000000
## 4     TRUE    Meadow 1.666667 4.933333     6.333333
## 5    FALSE   Orchard 0.000000 5.700000     9.000000
## 6    FALSE     Scrub 5.000000 4.700000     7.000000
## 7     TRUE     Scrub 9.000000 4.900000     3.500000
with(worms,tapply(Slope,list(Damp,Vegetation),mean))
##         Arable Grassland   Meadow Orchard Scrub
## FALSE 1.333333     3.625       NA       0     5
## TRUE        NA     4.000 1.666667      NA     9
detach(worms)
help(detach)
##########################################
data<- span=""> read.table('das.txt',header=T)
attach(data)
head(data)
##          y
## 1 2.514542
## 2 2.559668
## 3 2.460061
## 4 2.702720
## 5 2.571997
## 6 2.412833
plot(y)
which(y>10)
## integer(0)
y[50]
## [1] 2.179386
##########################################
data<- span=""> read.table('weather.txt',header=T)
names(data)
## [1] "upper" "lower" "rain"  "month" "yr"
attach(data) # Must read this commamnd everytime when You manipulate data!!
head(data)
##   upper lower rain month   yr
## 1  10.8   6.5 12.2     1 1987
## 2  10.5   4.5  1.3     1 1987
## 3   7.5  -1.0  0.1     1 1987
## 4   6.5  -3.3  1.1     1 1987
## 5  10.0   5.0  3.5     1 1987
## 6   8.0   3.0  0.1     1 1987
plot(factor(month),upper) # Call box-and-whisker plot

Nikkei225

28000-28550 up in the early session, down lately.