如何在for循环中替换多个可变数据帧中的零?

时间:2017-07-05 23:06:07

标签: r for-loop replace eval assign

所以我要在R中使用FOR循环处理1,000个数据帧,比如它们被命名为DF1到DF1000。我需要将数据帧中的所有0值替换为1。我尝试写如下。

let userEmail = userEmailTextField.text;
let userPassword = userPasswordTextField.text;

if((userEmail?.isEmpty)! || (userPassword?.isEmpty)!) {
    displayMyAlertMessage(userMessage: "All Fields are required.")
    return;
}

let myUrl = URL(string: "/UserLogin.php");
var request = URLRequest(url:myUrl!);
request.httpMethod = "POST";
let postString = "email\(userEmail)&password=\(userPassword)";

request.httpBody = postString.data(using: String.Encoding.utf8);

let task = URLSession.shared.dataTask(with: request as URLRequest) {
data, URLResponse, error in

    if error != nil {
        //print = ("error=\(error)");
        return
    }

    var err: Error?
    var json = JSONSerialization.jsonObject(with: data, options: .mutableContainers, error: &err) as? NSDictionary

    if let parseJSON = json {
        var resultValue:String = parseJSON["status"] as String!;
        print("result: \(resultValue)")


        if(resultValue == "Success") {
            //Login Succesful
            UserDefaults.standard.set(true, forKey:"isUserLoggedIn");
            UserDefaults.standard.synchronize();
            self.dismiss(animated: true, completion: nil);

        }
    }
}

task.resume()

这会出现错误("无法找到eval< - ")。我该如何解决这个问题?我尝试使用"分配"但得到一个不同的错误("赋值目标扩展到非语言对象")。

提前致谢, Alvo

1 个答案:

答案 0 :(得分:0)

使用基本assign功能,一种方法是DF全局环境中DF每个字符值replace到新for (i in 1:1000){ assign(paste0("DF", i), replace(eval(parse(text = paste0("DF", i))), eval(parse(text = paste0("DF", i))) == 0, 1), envir = .GlobalEnv) }

replace(DF,DF == 0, 1)

这类似于for循环之外的{{1}}。