合并具有相同ID

时间:2017-09-11 07:39:07

标签: r dataframe merge

我有一个这样的数据框:

df1:
    X1  X2   X3
1    1   4    7
2    2   5    8
3    3   6    9

class(df1[1,"X1"])

[1]"字符"

现在我有另一个这样的数据框:

df2:
    id    name
1     1       A
2     2       C
3     3       B
4     4       Z
5     5       X
6     6       G
7     7       E
8     8       Y
9     9       H

这里的id是数字

df1中的每个字符与df2中的数字相同。 这是我需要的结果:

    X1  X2   X3
1    A   Z    E
2    C   X    Y
3    B   G    H

我知道您可以使用相同的键合并两个表,但在这种情况下,我在df1上的键是表中的数据。

1 个答案:

答案 0 :(得分:2)

我们可以将@IBOutlet weak var deviceNameFeild: UILabel! @IBAction func backBtn(_ sender: UIButton) { //userDefaultにあるデーターを消す UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!) UserDefaults.standard.synchronize() let searchViewController = self.storyboard?.instantiateViewController(withIdentifier: "SearchViewController") as! SearchViewController self.navigationController?.pushViewController(searchViewController, animated: true) self.dismiss(animated: false, completion: nil) } override func viewDidLoad() { super.viewDidLoad() let backBtn = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.plain, target: navigationController, action: nil) navigationItem.leftBarButtonItem = backBtn let defaultValues = UserDefaults.standard if let name = defaultValues.string(forKey: "name"){ //setting the name to label deviceNameFeild.text = name }else{ //send back to login view controller } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } 用于此

match