# NOT RUN {
# construct data frame
mydata <- read.table(text="Severity Description
1 Mild
4 Moderate
3 Moderate
2 Mild
1 Severe", header=TRUE)
# only include those with a value of Moderate for Description
mydata <- Subset(rows=Description=="Moderate")
# use abbreviation and do not need the rows= for the first argument
mydata <- subs(Description=="Moderate")
# locate, that is, display only, the 2nd and 4th rows of data
Subset(row.names(mydata)=="2" | row.names(mydata)=="4")
# retain only the first and fourth rows of data, store in myd
myd <- Subset(c(1,4))
# delete only the first and fourth rows of data, store in myd
myd <- Subset(-c(1,4))
# built-in data table warpbreaks has several levels of wool
# and breaks plus continuous measure tension
# retain only the A level of wool and the L level of tension,
# and the one variable breaks
mydata <- Subset(wool=="A" & tension=="L", columns=breaks, data=warpbreaks)
# delete Years and Salary
mydata <- Read("Employee", in.lessR=TRUE, quiet=TRUE)
mydata <- Subset(columns=-c(Years, Salary))
# locate, display only, a specified row by its row.name
mydata <- Read("Employee", in.lessR=TRUE, quiet=TRUE)
Subset(row.names(mydata)=="Fulton, Scott")
# randomly extract 60% of the data
# generate code to create the hold out sample of the rest
mydata <- Read("Employee", in.lessR=TRUE, quiet=TRUE)
mysubset <- Subset(random=.6, holdout=TRUE)
# }
Run the code above in your browser using DataLab