所以我要在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
答案 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}}。