如何使用Excel / R处理重复项?

时间:2015-12-28 11:47:29

标签: r excel

我的数据在excel中看起来像这样:

if(soundCount > 0)
        {
            string[] smth;
            string pattern = @"\(((?:[^()]|(?R))+)\)";
            Regex match = new Regex(pattern, RegexOptions.None);

            MatchCollection matches = match.Matches(sound);
            smth = new string[matches.Count];

            int i=0;
            foreach (Match ma in matches)
            {
                smth[i] = Regex.Replace(ma.Value.Trim('(', ')'), @"\s+", "");
                Console.WriteLine(smth[i]);
                i++;
            }


            IList<sound_chips> newSoundchip = new List<sound_chips>();
            foreach(string s in smth)
            {
                newSoundchip.Add(new sound_chips() 
                { 
                    name = s.Split(',')[0].ToString(), 
                    manufacturer_id = Convert.ToInt32(setManufacturer(s.Split(',')[1].ToString())),
                    motherboards = newMotherboard
                });
            }
            insert.sound_chips.AddRange(newSoundchip);
        }

它下降了数百行,而我知道如何删除重复项,是否有一种方法可以在excel或r中区分重复项?

我的决赛桌理想情况下会是这样的

Name    Value
A        10
B        20
A        30
C        40
E        50
D        60
E        70
F        80
A        90
B        100

2 个答案:

答案 0 :(得分:6)

我们可以在make.unique

中使用R
df$Name <- make.unique(df$Name, sep='_')

答案 1 :(得分:4)

使用此公式:

=A2& IF(COUNTIF($A$2:$A2,A2)=1,"","_"&COUNTIF($A$2:$A2,A2)-1)

见下面的截图。

enter image description here