library(languageR)
#Exercise 1:
spanishMeta
##    Author YearOfBirth  TextName PubDate Nwords    FullName
## 1       C        1916 X14458gll    1983   2972        Cela
## 2       C        1916 X14459gll    1951   3040        Cela
## 3       C        1916 X14460gll    1956   3066        Cela
## 4       C        1916 X14461gll    1948   3044        Cela
## 5       C        1916 X14462gll    1942   3053        Cela
## 6       M        1943 X14463gll    1986   3013     Mendoza
## 7       M        1943 X14464gll    1992   3049     Mendoza
## 8       M        1943 X14465gll    1989   3042     Mendoza
## 9       M        1943 X14466gll    1982   3039     Mendoza
## 10      M        1943 X14467gll    2002   3045     Mendoza
## 11      V        1936 X14472gll    1965   3037 VargasLLosa
## 12      V        1936 X14473gll    1963   3067 VargasLLosa
## 13      V        1936 X14474gll    1977   3020 VargasLLosa
## 14      V        1936 X14475gll    1987   3016 VargasLLosa
## 15      V        1936 X14476gll    1981   3054 VargasLLosa
colnames(spanishMeta)
## [1] "Author"      "YearOfBirth" "TextName"    "PubDate"     "Nwords"     
## [6] "FullName"
nrow(spanishMeta)
## [1] 15
#Exercise 2:
xtabs(~spanishMeta$FullName, data = spanishMeta)
## spanishMeta$FullName
##        Cela     Mendoza VargasLLosa 
##           5           5           5
with(spanishMeta, tapply(PubDate, list(FullName), mean))
##        Cela     Mendoza VargasLLosa 
##      1956.0      1990.2      1974.6
#Exercise 3:
spanishMeta[order(spanishMeta$YearOfBirth, spanishMeta$Nwords), ]
##    Author YearOfBirth  TextName PubDate Nwords    FullName
## 1       C        1916 X14458gll    1983   2972        Cela
## 2       C        1916 X14459gll    1951   3040        Cela
## 4       C        1916 X14461gll    1948   3044        Cela
## 5       C        1916 X14462gll    1942   3053        Cela
## 3       C        1916 X14460gll    1956   3066        Cela
## 14      V        1936 X14475gll    1987   3016 VargasLLosa
## 13      V        1936 X14474gll    1977   3020 VargasLLosa
## 11      V        1936 X14472gll    1965   3037 VargasLLosa
## 15      V        1936 X14476gll    1981   3054 VargasLLosa
## 12      V        1936 X14473gll    1963   3067 VargasLLosa
## 6       M        1943 X14463gll    1986   3013     Mendoza
## 9       M        1943 X14466gll    1982   3039     Mendoza
## 8       M        1943 X14465gll    1989   3042     Mendoza
## 10      M        1943 X14467gll    2002   3045     Mendoza
## 7       M        1943 X14464gll    1992   3049     Mendoza
#Exercise 4:
spanishMeta$PubDate -> PubDate.v
PubDate.v = sort(PubDate.v)
help(sort)
sort(PubDate.v, decreasing = T) -> PubDate.v
#The question here says "sort the row names of meta"
#the rownames are just integers so I'm sorting the colnames #instead:
sort(colnames(spanishMeta))
## [1] "Author"      "FullName"    "Nwords"      "PubDate"     "TextName"   
## [6] "YearOfBirth"
#Exercise 5:
spanishMeta[spanishMeta$PubDate < 1980, ]
##    Author YearOfBirth  TextName PubDate Nwords    FullName
## 2       C        1916 X14459gll    1951   3040        Cela
## 3       C        1916 X14460gll    1956   3066        Cela
## 4       C        1916 X14461gll    1948   3044        Cela
## 5       C        1916 X14462gll    1942   3053        Cela
## 11      V        1936 X14472gll    1965   3037 VargasLLosa
## 12      V        1936 X14473gll    1963   3067 VargasLLosa
## 13      V        1936 X14474gll    1977   3020 VargasLLosa
#Exercise 6:
mean(spanishMeta$PubDate)
## [1] 1973.6
sum(spanishMeta$PubDate) / length(spanishMeta$PubDate)
## [1] 1973.6
#Exercise 7:
composer = data.frame(Author = c("Cela", "Mendoza", "VargasLLosa"), Favorite = c("Stravinsky", "Bach", "Villa-Lobos"))
newSpanishMeta = merge(spanishMeta, composer, by.x = "FullName", by.y = "Author")

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00