R-for循环错误:“'}'中出现意外的'}'”

问题描述

这是我要运行的模拟代码:

n_draws <- 1000

black <- rep(0,n_draws)
hispanic <- rep(0,n_draws)
asian <- rep(0,n_draws)
white <- rep(0,n_draws)


cutoff <- c(0.05,0.1,0.25,1)
draws <- runif(n_draws,1)

for (i in draws){
  
  if (draws[i] < cutoff[1]){
    
    black[i] <- 1
    
  } else if ((draws[i] >= cutoff[1]) & (draws[i] < cutoff[2])){
    
    hispanic[i] <- 1
    
  } else if ((draws[i] >= cutoff[2]) & (draws[i] < cutoff[3]){
    
    asian[i] <- 1
    
  } else {

white[i] <- 1

 }
}

基本上,我想在对应的列表中添加1,条件是该数字在(0,1)范围内。我不确定为什么会出错。有建议吗?

解决方法

您只是在 string[] inputs = { "name0.name1@xyz.com","name0.name1@xyz.com","name0.name1" }; string pattern = "(?'path'.*)@(?'site'.*)"; foreach(string input in inputs) { Match match = Regex.Match(input,pattern); string[] paths = match.Groups["path"].Value.Split(new char[] {'.'}).ToArray(); string site = match.Groups["site"].Value; Console.WriteLine("Path : '{0}',Site : '{1}'",string.Join("-",paths),site); } Console.ReadLine(); 之后缺少了一个右括号,在我的示例中也使用了cutoff[3],因为它更好一些

seq_along

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...