r - Issue with subsetting data; not picking up observations for one category -


i'm attempting subset data in r 1 column of spreadsheet 3 different categories: cod, haddock , whiting. reason however, haddock not working , saying there no observations subset, when in fact there should 51 - other 2 categories subsetting fine observations accounted for. can reasons this? spreadsheet appears ok, , doesn't seem contain obvious problems, there overlooking?

thanks

edit:

ok, here's part of data set here...

opcode                 species      distancefromcoast sa_f1_280714_c4_1   atlantic cod    583.69 sa_f1_280714_c4_1   haddock         583.69 sa_f1_280714_c4_1   whiting         583.69 sa_f1_290714_c2_10  atlantic cod    892.51 sa_f1_290714_c2_10  haddock         892.51 sa_f1_290714_c2_10  whiting         892.51 sa_f1_280714_c4_6   haddock         1080.5 sa_f1_280714_c4_6   whiting         1080.5 sa_f1_280714_c4_6   atlantic cod    1080.5 sa_f1_280714_c4_7   whiting         1030.59 sa_f1_280714_c4_7   haddock         1030.59 sa_f1_280714_c4_7   atlantic cod    1030.59 

maybe there class of variables. try

str(dat) 'data.frame':   12 obs. of  3 variables:  $ opcode           : factor w/ 4 levels "sa_f1_280714_c4_1",..: 1 1 1 4 4 4 2 2 2 3 ...  $ species          : factor w/ 3 levels "atlantic cod",..: 1 2 3 1 2 3 2 3 1 3 ...  $ distancefromcoast: num  584 584 584 893 893 ... 

a grouping operation should work fine,

library(dplyr) dat %>% group_by(species) %>%   summarise(ave.dist = mean(distancefromcoast)) #        species ave.dist # 1 atlantic cod 896.8225 # 2      haddock 896.8225 # 3      whiting 896.8225 

to graph group using ggplot2, need specify grouping option in aes (ie. color, shape, group, etc).

library(ggplot2) ggplot(dat, aes(x=species, y=distancefromcoast, fill=species)) + geom_bar(stat="identity") 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -