In: Computer Science
anyone can explain why this code in R doesn't work? i also tried to use filter function, no hope either!
b <- subset(sub,NEIGHBORHOOD == "HARLEM-CENTRAL")
the name of the variable is correct, the condition. is correct too.
b <- subset(sub,NEIGHBORHOOD == "HARLEM-CENTRAL",select=c(columnname1,columnname2,columnname3))
You have to add a select attribute also which contains the columns from sub. Since you have not provided the dataframe sub, I have simply given columnname1, columnname2, columnname3. There give the actual column names in sub which is your original data frame.
Example
x<-data.frame("roll"=1:11,
"name"=c("Jack","Jill","Jeeva","Smith","Bob","Smith","John","Mathew","Charles","Zen","Yug"),
"age"=c(20,22,30,28,30,21,19,18,25,25,29))
Here x is my dataframe.
newdata <- subset(x, age >= 25 & age < 30,select=c(roll,name,age)) will produce the following results.
# subset(x, age >= 25 & age < 30,select=c(roll,name,age))
roll name age
4 4 Smith 28
9 9 Charles 25
10 10 Zen 25
11 11 Yug 29