0

Not sure what exactly the error is here I'd appreciate some insight. My code is as follows, and I checked the structure of the df rbbq, there is definitely a column called 'Shrimp' in it.

    bbq1 = read.table('c:/Users/***/Documents/bbq.txt', sep=' ', 
    header=T)

    bbq2 = read.table('c:/Users/***/Documents/bbqshrimp.txt', sep=' ', 
    header=T)

    rbbq = merge(bbq1, bbq2, by='City')

    finalbbq = subset(rbbq, rbbq$Shrimp=="Yes", select=c('City', 'State' ))
    Error in `[.data.frame`(x, r, vars, drop = drop) : 
    undefined columns selected

I would use dplyr however that's not how the professor wants us to accomplish this. I am just trying to pull out the city and state of the locations which have, "Yes" for the Shrimp variable. Thanks for any help! This question is specific to the subset function, and not just a matter of calling up the specific lines.

EDIT: Final workaround was to assign my dataframe to another name, and that did the trick.

1 Answers1

1

Remove the rbbq$from rbbq$Shrimp. Also, pretty sure city and state don't need to be quoted.

iod
  • 7,412
  • 2
  • 17
  • 36
  • > finalbbq = subset(rbbq, Shrimp=="Yes", select=c(City, State)) Error in eval(substitute(select), nl, parent.frame()) : object 'State' not found > finalbbq = subset(rbbq, Shrimp=="Yes", select=c('City', 'State')) Error in `[.data.frame`(x, r, vars, drop = drop) : undefined columns selected –  Sep 29 '18 at 18:28
  • `object 'State' not found`... – Henrik Sep 29 '18 at 18:30