I have a data frame called fin
:
str(fin)
'data.frame': 158 obs. of 9 variables:
$ Species : chr "TRAT" "TRAT" "TRAT" "WRAT" ...
$ Site : chr "BAN" "BEX" "BEX" "BEX" ...
$ Year : chr "2011" "2010" "2011" "2012" ...
$ FR.CoYear: num 35.7 123.6 136.4 215.8 145.2 ...
$ Sample : int 31 NA 929 809 NA NA NA 30 215 NA ...
$ Young : num 16 NA 828 709 NA NA NA 45 235 NA ...
$ SiteYear : Factor w/ 65 levels "BAN 2011","BAN 2012",..: 1 4 5 6 7 1
I would like to plot FR.CoYear
against (fin$Young / fin$Sample)
separately for each of the 5 species in $Species
.
I tried the ways suggested here; but none are currently working, I would be very grateful for guidance - is this just a syntax problem?
This is what I have tried:
with(subset(fin,fin$Species == "TRAT"), plot(fin$FR.CoYear, fin$Young /fin$Sample))
## runs without error but no plot is produced
with(fin[fin$Species == "TRAT",], plot((fin$FR.CoYear, fin$Young / fin$Sample))
##gives the error: unexpected ',' in "with(fin[fin$Species == "TRAT",], plot((fin$FR.CoYear,"
plot(fin$FR.CoYear[fin$Species == "BLKI"],fin$Young / fin$Sample[fin$Species == "BLKI"])
##Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
I apologise if this is very basic, but am teaching myself R.