# 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")
# only include those with a value of Moderate for Description
# 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")
# only retain females and Years and Salary as variables in dataEmployee
# write result to newdata
data(dataEmployee)
newdata <- Subset(Gender=="F", columns=c(Years, Salary),
data=dataEmployee)
# delete Years and Salary from datEmployee
mydata <- Read("Employee", format="lessR")
mydata <- Subset(columns=-c(Years, Salary))
# locate, display only, a specified row by its row.name
mydata <- Read("Employee", format="lessR")
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", format="lessR")
mysubset <- Subset(.6, holdout=TRUE)
Run the code above in your browser using DataLab