根据R中的ID查找唯一行

时间:2015-04-02 08:42:16

标签: r subset

这只是我整个数据框的一小部分(年份和鱼的科学名称):

dput(fishery)
structure(list(Year = c(2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L), Scientific.Name = structure(c(15L, 
1L, 17L, 18L, 1L, 1L, 18L, 1L, 18L, 19L, 1L, 15L, 1L, 18L, 15L, 
17L, 15L, 1L, 18L, 1L, 18L, 1L, 1L, 17L, 18L, 18L, 17L, 1L, 15L, 
18L, 18L, 18L, 1L, 17L, 1L, 1L, 1L, 1L, 17L, 18L, 17L, 18L, 18L, 
22L, 15L, 18L, 18L, 18L, 2L, 1L, 1L, 18L, 18L, 18L, 1L, 18L, 
2L, 17L, 17L, 19L, 7L, 18L, 2L, 18L, 17L, 7L, 18L, 18L, 18L, 
1L, 1L, 17L, 18L, 18L, 1L, 1L, 17L, 19L, 17L, 1L, 1L, 1L, 17L, 
1L, 18L, 18L, 18L, 18L, 18L, 17L, 18L, 13L, 17L, 17L, 18L, 17L, 
7L, 15L, 16L, 1L), .Label = c("Aristaeomorpha foliacea", "Aristeus antennatus", 
"Centrophorus granulosus", "Citharus linguatula", "Dipturus oxyrinchus", 
"Gadus morhua", "Helicolenus dactylopterus", "Heptranchias perlo", 
"Hexanchus griseus", "Lepidopus caudatus", "Lepidorhombus boscii", 
"Leucoraja melitensis", "Lophius budegassa", "Lophius spp", "Merluccius merluccius", 
"Mullus surmuletus", "Nephrops norvegicus", "Parapenaeus longirostris", 
"Phycis blennoides", "Raja clavata", "Raja montagui", "Scyliorhinus canicula", 
"Todarodes sagittatus", "Torpedo nobiliana", "Trachurus spp", 
"Aspitrigla cuculus", "Illex coindetii", "Leucoraja circularis", 
"Sepia elegans"), class = "factor")), class = "data.frame", row.names = c(NA, 
-100L), .Names = c("Year", "Scientific.Name"))

我想知道每个Scientific.Name比较的Year字段。

例如,Aristaeomorpha foliacea列的名称Scientific.Name是2009年和2010年的常见条目,而Scyliorhinus canicula仅在2009年而非2010年被捕获。

我希望自己足够清楚......

BTW,整个数据框架非常庞大..

由于

1 个答案:

答案 0 :(得分:2)

不会像table(fishery$Scientific.Name , fishery$Year)那样简单吗?

我不太明白这些年份与上述例子中的名字的映射。