Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.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
R 将其他向量元素替换为0_R - Fatal编程技术网

R 将其他向量元素替换为0

R 将其他向量元素替换为0,r,R,假设要有条件地替换向量的所有元素。例如: a <- c("A","T","G","A") b <- c(1,4,1,5) a在a中按条件复制b和子集c c <- b c[a!="A"] <- 0 c或其他路线: c=ifelse(a=="A",b,0) 这就是设计的目的: replace(b,a!='A',0); ## [1] 1 0 0 5 抱歉17

假设要有条件地替换向量的所有元素。例如:

a <- c("A","T","G","A")
b <- c(1,4,1,5)

a在
a
中按条件复制
b
和子集
c

c <- b
c[a!="A"] <- 0
c或其他路线:

c=ifelse(a=="A",b,0)
这就是设计的目的:

replace(b,a!='A',0);
## [1] 1 0 0 5
抱歉17<18:“[
replace(b,a!='A',0);
## [1] 1 0 0 5