0

I have an S4 object 'DATA' with three slots - the structure looks like this (sorry, I don't know how to create an example, so this a simplified structure of what I'm working with)

---Coordinates: @coo (e.g. 'Name_A') is a 2x20 matrix where, there are 6 matrices with names

---Names: @names Name_A Name_B Name_C Name_D Name_E Name_F and each Name has one of two Factors

---Factors: @fac Factor_A Factor_B

How do I subset (select) @coo data where @fac = Factor_A? I've tried a numer of combinations of dataframe type selections using [] notation with getElement but this is clearly not correct. Thanks.

EDIT Repeatable example - this is a horrific way of doing this I know....

library(Momocs)

The input data file you read in looks like this (called "test.chc", where this is the output from another application)

 [1] "sampleA 322 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"
 [2] "sampleB 231 5 4 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"    
 [3] "sampleC 489 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"   
 [4] "sampleD 323 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"    
 [5] "sampleE 381 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"    
 [6] "sampleF 342 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"    
 [7] "sampleG 327 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"    
 [8] "sampleH 336 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"    
 [9] "sampleI 147 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"
[10] "sampleJ 654 6 5 4 4 4 4 4 6 5 4 4 4 6 0 0 0 6 6 4 6 5 4 4 4 4 3 2 4 3 2 4 4 -1"   

and

grps<- data.frame(Groups=(rep(letters[1:2],5)))

c.S4obj <-chc2Coo("test.chc")

c.S4obj@fac <-grps

str(c.S4obj)

So, the question is, how to select data for a specific group (a or b) and return an S4 class object?

Vincent Bonhomme
  • 7,235
  • 2
  • 27
  • 38
user2175481
  • 147
  • 1
  • 8
  • 1
    Is this an S4 class you've defined? Do you want an S4 class of the same type returned or do you just want the data? Looks like `@coo` has two columns and `@fac` has two values, does each value of `@fac` correspond to a column of `@coo`? It would be easier to help if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). – MrFlick Jul 06 '15 at 23:00
  • OK, have added an example in the best way I know how - not ideal i agree. to answer your question, yes, an S4 class object should be returned, keeping the structure for down-stream analysis in the Momocs library. – user2175481 Jul 07 '15 at 12:53

1 Answers1

0

Momocs now uses S3 classes and it's much easier to retrieve data. If you're still doing morphometrics, it's worth having a look to the 1.0.0 version on CRAN and its vignette.

Vincent Bonhomme
  • 7,235
  • 2
  • 27
  • 38