# 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
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
subs(Description=="Moderate")
# locate, that is, display, the second row of data
# note that mydata must be explicitly specified
locate(row.names(mydata)==2)
# only retain females and Years and Salary as variables in datEmployee
data(dataEmployee)
Subset(rows=Gender=="F", columns=c(Years, Salary), dframe=dataEmployee)
# delete Years and Salary from datEmployee
Read(lessR.data="Employee")
Subset(columns=-c(Years, Salary))
# locate only women with more than 10 years employment
# save in a new data frame, women
Read(lessR.data="Employee")
women <- locate(Gender=="F" & Years>10)
# locate all rows for females, display at console and save into mynewdata
Read(lessR.data="Employee")
mynewdata <- locate(Gender=="F")
# locate row by its row.name, here the employee's name
Read(lessR.data="Employee")
locate(row.names(mydata)=="Fulton, Scott")
# randomly extract 60\% of the data and create a hold-out sample
Read(lessR.data="Employee")
Subset(.6)
Run the code above in your browser using DataLab