J Phelps
J Phelps

Reputation: 1

Why are some of my created vectors working and others are not for the same method of making sub datasets?

I'm working with a dataset that contains multiple species. To make visualizing the data easier, I have made vectors to divide the data by species.

Here is my data: list of species with sex, weight, and forewing length data - it is part of my datatable

species sex weight forewing length
chlosyne janis female 0.0555 3.319
chlosyne janis male 0.0272 3.114
chlosyne janis male 0.0364 2.756
chlosyne janis male 0.0278 2.678
chlosyne erodyle female 0.0593 3.157
chlosyne lacinia crocale male 0.0364 2.756
chlosyne lacinia crocale female 0.0143 2.688
chlosyne lacinia crocale male 0.0085 2.537
chlosyne lacinia crocale male 0.011 2.25
chlosyne lacinia lacinia male 0.0164 2.801
chlosyne hippochrome male 0.0301 1.963
chlosyne acastus neumoegenio male 0.0121 1.55
anthanassa texana seminole female 0.0225 1.809
anthanassa texana seminole female 0.0139 1.491
anthanassa texana seminole female 0.0179 1.869
anthanassa texana seminole female 0.0186 1.806
anthanassa texana seminole female 0.0232 2.125
anthanassa texana seminole female 0.0143 1.682
anthanassa texana seminole male 0.017 1.763
anthanassa texana seminole male 0.0157 1.593
anthanassa texana seminole male 0.0142 1.393
anthanassa texana seminole male 0.0152 1.463
anthanassa texana seminole male 0.0105 1.515
anthanassa texana seminole male 0.0079 1.485
anthanassa texana seminole male 0.0185 1.592
anthanassa texana seminole male 0.0143 1.505
anthanassa texana texana female 0.0225 1.767
anthanassa texana texana female 0.0261 1.869
anthanassa texana texana male 0.0206 1.759

This is a section of the code I've been running:

chlosyne.janis <- tribe.df[tribe.df$species == "chlosyne janis",] 
head(chlosyne.janis) 

chlosyne.erodyle <- tribe.df[tribe.df$species == "chlosyne erodyle",] 
head(chlosyne.erodyle) 

c.lacinia.crocale <- tribe.df[tribe.df$species == "chlosyne lacinia crocale",] 
head(c.lacinia.crocale) 

c.lacinia.lacinia <- tribe.df[tribe.df$species == "chlosyne lacinia lacinia",] 
head(c.lacinia.lacinia) 

chlosyne.hippochrome <- tribe.df[tribe.df$species == "chlosyne hippochrome",] 
head(chlosyne.hippochrome) 

c.acastus.neumoegenio <- tribe.df[tribe.df$species == "chlosyne acastus neumoegenio",] 
head(c.acastus.neumoegenio) 

a.texana.seminole <- tribe.df[tribe.df$species == "anthanassa texana seminole",] 
head(a.texana.seminole) 

a.texana.texana <- tribe.df[tribe.df$species == "anthanassa texana texana",] 
head(a.texana.texana)

For some of the vectors, I can see the number of observations with the associated variables, and for others it will give me 0 observations with the associated variables.

I have double check spelling in the dataset and in the code. c.lacinia.lacinia and c.lacinia.crocale consistently come up with 0 observations, even after reloading the dataset.

Is there a better way to make a vector that retains the observations?

Upvotes: 0

Views: 35

Answers (1)

kukuk1de
kukuk1de

Reputation: 406

If it is a data.table replace chlosyne.janis <- tribe.df[tribe.df$species == "chlosyne janis",] with chlosyne.janis <- tribe.df[species == "chlosyne janis",]

Upvotes: 0

Related Questions