I want to compute my data according to rule that number+W is number*2.
dat="1W 16 2W 16
1 16 2W 0
1W 16 16 0
4 64 64 0"
data=read.table(text=dat,header=F)
apply(data,c(1,2),function(y){
if(grep(pattern="W",y) ==1 )
{ gsub("W",paste("*",2,sep=""),y)->s;
eval(parse(text=s));
} else
{y <- y }
})
But I get the output:
Error in if (grep(pattern = "W", y) == 1) { : argument is of length zero
Why? If y matches "W" then the value is 1, what is wrong with my code?
See Question&Answers more detail:os