Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在数字对于1:lengthto中的i。replace@Hemmo有关详细信息,请参见下文this@Hemmo非常感谢,这也行!现在我觉得自己像个裸体@罗兰:是的,那当然也行,只是想指出代码中的错误,而不是改进;无论如何,alexwhan的解决方案更好。你的循环中缺少了1:1,因为我在lengthto.replace->for我在1:lengthto。replace@Hemmo有关详细信息,请参见下文this@Hemmo非常感谢,这也行!现在我觉得自己像个裸体@罗兰:是的,那当然也行,只是想指出代码中的错误,而不是改进;无论如何,阿列克肖恩的解决方案更好。_R_For Loop_Gsub - Fatal编程技术网

在数字对于1:lengthto中的i。replace@Hemmo有关详细信息,请参见下文this@Hemmo非常感谢,这也行!现在我觉得自己像个裸体@罗兰:是的,那当然也行,只是想指出代码中的错误,而不是改进;无论如何,alexwhan的解决方案更好。你的循环中缺少了1:1,因为我在lengthto.replace->for我在1:lengthto。replace@Hemmo有关详细信息,请参见下文this@Hemmo非常感谢,这也行!现在我觉得自己像个裸体@罗兰:是的,那当然也行,只是想指出代码中的错误,而不是改进;无论如何,阿列克肖恩的解决方案更好。

在数字对于1:lengthto中的i。replace@Hemmo有关详细信息,请参见下文this@Hemmo非常感谢,这也行!现在我觉得自己像个裸体@罗兰:是的,那当然也行,只是想指出代码中的错误,而不是改进;无论如何,alexwhan的解决方案更好。你的循环中缺少了1:1,因为我在lengthto.replace->for我在1:lengthto。replace@Hemmo有关详细信息,请参见下文this@Hemmo非常感谢,这也行!现在我觉得自己像个裸体@罗兰:是的,那当然也行,只是想指出代码中的错误,而不是改进;无论如何,阿列克肖恩的解决方案更好。,r,for-loop,gsub,R,For Loop,Gsub,我写这篇文章是为了找到1:到9:的任何实例,并用01:到09:替换它,同时保留10:或更大的完整性。下面是一个示例脚本: region = c("18:1-100","16:1-100","X:1-100","2:1-100","4:1-100") to.replace=grep("^[[:digit:]]:", region) replacement=grep("^[[:digit:]]:", region, value=T) replacement=paste(0,replacement,

我写这篇文章是为了找到1:到9:的任何实例,并用01:到09:替换它,同时保留10:或更大的完整性。下面是一个示例脚本:

region = c("18:1-100","16:1-100","X:1-100","2:1-100","4:1-100")

to.replace=grep("^[[:digit:]]:", region)
replacement=grep("^[[:digit:]]:", region, value=T)
replacement=paste(0,replacement,sep="")

for (i in length(to.replace)){
  region[to.replace[i]]=replacement[i]
}

它只在区域中最后一次出现时起作用,因此我认为我的for循环有问题,我不知道是什么。

只需将for循环替换为:

region[to.replace] <- replacement

只需将for循环替换为:

region[to.replace] <- replacement

你可以用一个圈跑过去


你可以用一个圈跑过去


您的循环中缺少1:对于lengthto中的i。替换->对于1:lengthto中的i。replace@Hemmo有关详细信息,请参见下文this@Hemmo非常感谢,这也行!现在我觉得自己像个裸体@罗兰:是的,那当然也行,只是想指出代码中的错误,而不是改进;无论如何,alexwhan的解决方案更好。你的循环中缺少了1:1,因为我在lengthto.replace->for我在1:lengthto。replace@Hemmo有关详细信息,请参见下文this@Hemmo非常感谢,这也行!现在我觉得自己像个裸体@罗兰:是的,那当然也行,只是想指出代码中的错误,而不是改进;无论如何,阿列克肖恩的解决方案更好。