Question

In: Computer Science

anyone can explain why this code in R doesn't work? i also tried to use filter...

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.

Solutions

Expert Solution

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


Related Solutions

can anyone explain the code from R below? spam is a dataset sample <- sample( c(TRUE,...
can anyone explain the code from R below? spam is a dataset sample <- sample( c(TRUE, FALSE), nrow(spam), replace=TRUE) train <- spam[sample,] test <- spam[!sample,] when i run train and test, we got two different datasets that are split from the original spam dataset. But i don't understand the first line of code. not sure why this line of code can split data into two sets.
Does anyone know the code to use in R programming to create a scatter plot?
Does anyone know the code to use in R programming to create a scatter plot?
Does anyone know the code to use in R programming to create a box plot?
Does anyone know the code to use in R programming to create a box plot?
Can anyone explain to me why I am getting an access violation when I try to...
Can anyone explain to me why I am getting an access violation when I try to add notes? It occurs when I try to set the "pLast" pointer to the previous node (for a doubly linked list). The code worked as singly linked list. When I added a "pLast" pointer and the needed code to make it a doubly linked list everything broke. #include <iostream> #include <stdlib.h> using namespace std; //build class that has a private function to inc count....
Why Newtonian mechanics doesn't work at velocities close to that of the speed of light? I...
Why Newtonian mechanics doesn't work at velocities close to that of the speed of light? I know that mass tends to become infinite at v=c but why does it fail if v is close to c but not exactly c?
How can I use the R language to code a new group to screen some variables?...
How can I use the R language to code a new group to screen some variables? for example, there is a data set include 5 candy's brand: a b c d e I just want to create a new group include a, b, c variable. How can I code it?
USE R CODING! Pleaseee I need the code With R coding Obs: it supposed to use...
USE R CODING! Pleaseee I need the code With R coding Obs: it supposed to use probability density function like X ~ Binomial( n ,p ) dbinom(X=?, n, prob) pbinom(X=?, n, prob) rbinmo(幾個符合二項分配的X, n, prob) X~Poisson (lamda) dpois(X=?, lamda) ppois (X=?, lamda) rpois (X, lamda) **Suppose the random variable X obeys the binomial allocation B (n=100, p=0.1) (a) Use X as the binomial allocation to calculate P(12≤X≤14) (b) In practice, when np ≥ 5 and n(1-p) ≥ 5, X will...
Why doesn't the Uniform Commercial Code cover patents? Please explain with a couple sentences.
Why doesn't the Uniform Commercial Code cover patents? Please explain with a couple sentences.
Does anyone know how to import data from Microsoft Excel code to use in R programming...
Does anyone know how to import data from Microsoft Excel code to use in R programming ?
Why would anyone want to work as a PCT?
Why would anyone want to work as a PCT?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT