Closed EmmalineSheahan closed 6 years ago
Dr. Sotka helped me figure out a way to make it work:
# creating dir
trop_atlantic_names <- vector("list", length = 6)
for (i in 1:6) {
for (j in 1:534) {
#print(any(trop_atlantic_stack[[i]][[j]]@data@values==1))
if (sum(trop_atlantic_stack[[i]][[j]]@data@values==1,na.rm=T)>0)
{
trop_atlantic_names[[i]][[j]] <- trop_atlantic_stack[[i]][[j]]@data@names
} else {trop_atlantic_names[[i]][[j]] <- NA}
}
}
So now I have a list of names of which species are in the realm
Nice! Thanks for the update
On Jun 2, 2018, at 5:55 PM, EmmalineSheahan notifications@github.com wrote:
Dr. Sotka helped me figure out a way to make it work:
creating dir
trop_atlantic_names <- vector("list", length = 6) for (i in 1:6) { for (j in 1:534) {
print(any(trop_atlantic_stack[[i]][[j]]@data@values==1))
if (sum(trop_atlantic_stack[[i]][[j]]@data@values==1,na.rm=T)>0) { trop_atlantic_names[[i]][[j]] <- trop_atlantic_stack[[i]][[j]]@data@names } else {trop_atlantic_names[[i]][[j]] <- NA}
} } So now I have a list of names of which species are in the realm
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
So in order to use the functions I wrote earlier to conduct the phylogenetic analyses on the regional rasters, I need to create a directory of the species that appear in the two regions. My current issue is that all 534 species are still listed in the stacks for each region because I used the intersect function, even though not all of them actually occur there. I wrote this code in order to drop the species layers from the raster stack where it's NA for every cell (so the species doesn't occur in the region at all) so I can pull out the layer names at the end of it and see which species are there and which aren't:
but it keeps giving me this error:
Error in .local(x, ...) : not a valid subset
I think the problem is in the dropLayer function, because for some reason R was having trouble registering even a number in the place of j even though the documentation for that function says it should be an integer