Is there a set of R functions analogous to intersect, union, etc. which act on vectors of coordinates? Take a two collections of locations in N dimensions, each of which could be viewed as N-row by M-location array, and find the common locations (i.e. columns), and so on. I suppose this could be done with a couple *apply lines to compare every column in one array to the columns of the other, but was hoping for something faster or neater.
Is there a set of R functions analogous to intersect , union , etc.
Share
There is a ‘sets’ package, but the simplest solution would be to use the base set operations:
union, ,intersect, andsetdiffon the results ofpastewith a separator such as"_". If these are represented as ‘numeric” values you may need to make decsions about what really means “equality” and for that someround-ing ortrunc-cation may be needed.Another thought is that implementation might be more self-documenting in the columnwise arrangement you describe to use the “plyr” function:
colwise. I’m not a dedicated user of plyr methods, but this appears to be how it might start:Although the description of the function suggests it should work as a standalone function on a dataframe, all of the illustrated uses are with
ddply.