在Windows下使用Rs替换gsub错误

时间:2017-01-21 01:55:49

标签: r linux windows gsub

我在Ubuntu下开发了以下功能R脚本

Node* searchNode(Node* root, int value){
    Node* temp = root;
    while (temp != NULL){
        if (temp->val == value){
            return temp;
        }
        else if (temp->val < value){
            temp = temp->right;
        }
        else if (temp->val > value){
            temp = temp->left;
        }
    }
}

Node* sibling(Node* node){
    if ((node == NULL) || (node->parent == NULL)){
        return NULL;
    }
    if (node == node->parent->left){
        return node->parent->right;
    }
    else{
        return node->parent->left;
    }
}
Node* maxNode(Node* node){
    while (node->right != NULL){
        node = node->left;
    }
    return node;
}
void replaceNode(Node* old, Node* new_node){
    if (old->parent == NULL){
        old = new_node;
    }
    else{
        if (old == old->parent->left){
            old->parent->left = new_node;
        }
        else{
            old->parent->right = new_node;
        }
    }
    if (new_node != NULL){
        new_node->parent = old->parent;
    }
}
void deleteNode(Node* root, int value){

    Node* child;
    Node* temp = searchNode(root, value);
    if (temp == NULL){
        return;
    }
    if (temp->left != NULL&&temp->right != NULL){
        Node* pred = maxNode(temp->right);
        temp->val = pred->val;
        temp = pred;
    }
    if (temp->left == NULL || temp->right == NULL){
        if (temp->right == NULL && temp->left == NULL){
            child = temp;
        }
        else if (temp->right == NULL){
            child = temp->left;
        }
        else{
            child = temp->right;
        }
    }
        if (temp->color == 1){
            temp->color = child->color;
            delete_case1(root, child);
        }

        replaceNode(temp, child);
        delete temp;

}
void delete_case6(Node* root, Node* n)
{
    Node *s = sibling(n);

    s->color = n->parent->color;
    n->parent->color = 1;

    if (n == n->parent->left) {
        s->right->color = 1;
        rotate_left(root, n->parent);
    }
    else {
        s->left->color = 1;
        rotate_right(root, n->parent);
    }
}
void delete_case5(Node* root, Node* n)
{
    Node *s = sibling(n);

    if (s->color == 1) {
        if ((n == n->parent->left) &&(s->right->color == 1) &&(s->left->color == 0)) {
            s->color = 0;
            s->left->color = 1;
            rotate_right(root, s);
        }else if ((n == n->parent->right) &&(s->left->color == 1) &&(s->right->color == 0)) {
            s->color = 0;
            s->right->color = 1;
            rotate_left(root, s);
        }
    }
    delete_case6(root, n);
}
void delete_case4(Node* root, Node* n)
{
    Node *s = sibling(n);

        if ((n->parent->color == 0) && (s->color == 1) && (s->left->color == 1) && (s->right->color == 1)) {
            s->color = 0;
            n->parent->color = 1;
        }
        else{
            delete_case5(root, n);
        }

    }
void delete_case3(Node* root, Node* n){
    Node* s = sibling(n);
    if ((n->parent->color == 1) &&(s->color == 1) &&(s->left->color == 1) &&(s->right->color == 1)) {
        s->color = 0;
        delete_case1(root, n->parent);
    }
    else
        delete_case4(root, n);
}
void delete_case2(Node* root, Node* n){
    Node *s = sibling(n);
    if (s->color == 0){
        n->parent->color = 0;
        s->color = 1;
        if (n == n->parent->left){
            rotate_left(root, n->parent);
        }
        else if (n == n->parent->right){
            rotate_right(root, n->parent);
        }
    }
    delete_case3(root, n);
}
void delete_case1(Node* root,Node* n){
    if (n->parent != NULL){
        delete_case2(root,n);
    }
}



void main(){
    ABTree* ABtree=new ABTree;
    ABtree->root = NULL;
    insertTree(ABtree->root, 15);
    insertTree(ABtree->root, 8);
    insertTree(ABtree->root, 2);
    insertTree(ABtree->root, 9);
    insertTree(ABtree->root, 10);
    insertTree(ABtree->root, 12);
    insertTree(ABtree->root, 18);
    insertTree(ABtree->root, 25);
    insertTree(ABtree->root, 20);
    printTree(ABtree->root);
    Node* search=searchNode(ABtree->root, 18);
    cout << endl;
    cout << search->val<<endl;
    deleteNode(ABtree->root, 8);
    printTree(ABtree->root);
}
在Windows下

,它失败了。具体来说,

lbcordiprice2 <- gsub('\n', '', lbcordiprice1)
lbcordiprice3 <- gsub('\t', '', lbcordiprice2)
lbcordiprice4 <- gsub(' ', '', lbcordiprice3)
lbcordiprice5 <- gsub('€', '', lbcordiprice4)
lbcordiprice6 <- gsub(' ', '', lbcordiprice5)
lbcordiprice7 <- as.numeric(lbcordiprice6)

无法转换以下向量

lbcordiprice4  [1]“750€”“4900€”“9000€”“21900€”“40€”“4390€”“100€”“1€”“30€”“23900€”“210€”
[12]“3200€”“22900€”“25€”“30€”“30000€”“400€”“20€”“16900€”“15€”“20€”“180€”

进入

lbcordiprice5  [1]“750”“4900”“9000”“21900”“40”“4390”“100”“1”“30”“23900”“210”
[12]“3200”“22900”“25”“30”“30000”“400”“20”“16900”“15”“20”“180”

我感觉问题在于编码,但我无法正确理解。

0 个答案:

没有答案