I would like to be able to subset the list of objects in my Global Environment by class.
i.e. from the list created by running
ls()
I would like to be able to make a shorter list that only has the names of the objects that belong to specific class e.g. xts or POSIXlt
Thanks in advance
You could retrieve
ls()and check the class of everything. It may not be particularly efficient though, as it does the filtering afterls()and not within.The
get(var)gets the variable corresponding to the string invar, so ifvaris"a"thenget(var)retrieves 1 (being the value of variablea).As @VincentZoonekynd notes below – it is possible for objects to have multiple classes. Soo
class(some_xts_object)isc("xts","zoo")— the above method will returnsome_xts_objectif you search forxtsobjects, but also if you search forzooobjects.