Professional Documents
Culture Documents
This file shows the code that is run and the result that will be shown in R if there is any, where the
highlighted blue lines are the code and the highlighted black lines are the results shown in R.
Practice 1
#1. What is the dimension of our dataset?
> dim(mydatacsv)
[1] 150 5
#2. Assign the value of the cell [2,3] to the new variable var1
var1=mydatacsv[2,3]
#3. Assign the value of the cell [10,4] to the new variable var2
var2=mydatacsv[10,4]
Practice 2a.
#1. Read into R the dataset pubfileb.csv.
public<- read.table('pubfileb.csv', sep=',', header=T)
#3. Extract the variable povpct, income as percent of poverty level (column 35) as a new variable.
povpct=public[,35]
#4. Extract the variable ms, marital status (column 5) as a new variable.
ms= public[,5]
#5. Obtain the minimum, maximum, mean, variance, median for the variable povpct and store them in
separate variables.
m=mean(povpct)
var=var(povpct)
min=min(povpct)
max=max(povpct)
med=median(povpct)
#6. Export your extracted variables as a .csv file and the dataset as a tab delimited .txt file.
write.csv(povpct,file="povpct.csv")
write.table(public,file="public.txt", sep="\t")