Sample Exam Questions
Below you will find some sample exam questions.
- The following regular expression
is meant to find a string containing dollars and
cents where the cents are optional:
grep("\\$[0-9]*\\.[0-9]{2}", x)
Find three such character strings
that are not handled by this regular expression.
- For the bank database used in class (tables would be provided),
describe the results table from the following
query:
SELECT CustNo, SUM(Balance) FROM Reg R, Acct A
WHERE A.No = R.AcctNo GROUP BY A.Branch ;
-
How would you generate a pseudo-random number using the
accepatnce rejection method from the following distribution.
Give your answer in pseudo-code with sketches.
f(x) = (3/4)(1 - x^2)
for -1 < x < 1,
and 0 otherwise.
- Describe the following graphic using Wilkinson's
Grammar of Graphs:
-
Correct the following malformed XML:
<?xml version="1.0" ?>
<country>
<state>
<gml:name abb=AZ>Arizona</gml:name>
<county>
<gml:name>Apache</gml:name>
<gml:location>
<Point>
<gml:coord>
<gml:X>-109</gml:X><gml:Y>35</gml:Y></gml:coord>
</point>
</gml:location>
</county>
<county>
<gml:name>Cochise</gml:name>
<gml:location>
<Point>
<gml:coord>
<gml:X>-109</gml:X><gml:Y>31</gml:coord>
</Point>
</gml:location>
</county>
</state>
</country>
-
Rewrite the following for-loop using one of the apply functions.
for (i in 1:length(files) {
newMsg[[i]] = readLines(paste(x,files[i],sep"/"))
newMsg[[i]] = cleanMsg(newMsg[[i]])
}
-
Given the handler function below for the xmlTreeParse, describe
what is being collected.
linkHandlers = function()
{
n = ""
a = function(x){
href = xmlGetAttr(x, "href")
if(!is.null(href)) n <<- c(n, href)
}
list(a = a, .value = function() n)
}
- Use vector operations to simplify the following:
percentSpam = function(file) {
totalCount = 0
spamCount = 0
for (i in file) {
if (substr(i, 1, 1) == "s" {
spamCount = spamCount + 1
}
totalCount = totalCount + 1
}
}