Data Preprocessing Assignment Solutions: Error in ' (.Data - Frame' (Mtcars, 1:20) ) : Undefined Columns Selected
Data Preprocessing Assignment Solutions: Error in ' (.Data - Frame' (Mtcars, 1:20) ) : Undefined Columns Selected
Solutions
1. The command mtcars[1:20] returns an error because there is no column defined hence we are
getting error.
The resultant output shown was - Error in `[.data.frame`(mtcars, 1:20)] : undefined columns
selected
It differs from the similar command mtcars[1:20, ] as in this new command, the column is
defined. The “ “ defines column in the command and as column is specified it will not show any
error.
2. i. mtcars[mtcars$cyl = 4, ]
answer - mtcars[mtcars$cyl == 4, ]
ii. mtcars[-1:4, ]
answer - mtcars[1:4, ]
iv. mtcars[mtcars$cyl == 4 | 6, ]
4. Records with cylinder greater than 4 and weighs less than mean weight are -
mean(mtcars$wt)
Q4<- subset(mtcars,cyl > 4 & mtcars,wt < 3.21725, )
BP<- Building_Permits
BP$`Permit Creation Date`<-as.Date(BP$`Permit Creation Date`, format = "%m/%d/%Y")
q1<-BP[BP$`Permit Creation Date` < "2013-1-1", ]
q2<-BP[order(BP$`Permit Creation Date`), ]
q3<-tail(q2,1)
q4<-head(q2,1)
NEW
OLD
6.
i) Extraction of the building records with permit date after 1 January 2015 -
q5<-BP[BP$`Permit Creation Date` > "2015-1-1", ]
ii) Finding the oldest and newest permit date records for the buildings in Block 326 -
BP$Block<-as.numeric(BP$Block)
q6<-BP[order(BP$`Permit Creation Date`), ]
q7<-subset(q6,q6$Block =="326", )
q8<-tail(q7,1)
q9<-head(q7,1)
NEW
OLD
iii) extracting the building records with permit date after 1 January 2015 and completed
after 1 January 2018 -