I have a dataframe:
smoke <- matrix(c(51,43,22,92,28,21,68,22,9),ncol=3,byrow=TRUE)
colnames(smoke) <- c("High","Low","Middle")
smoke=as.data.frame(smoke);smoke$sit[1]="bit"; smoke$sit[2]="bsa"
smoke$sit[3]="bu"
smoke
High Low Middle sit
1 51 43 22 bit
2 92 28 21 bsa
3 68 22 9 bu
I want apply my simple function:
myf<- function(c,r){
x=5*c+r
write.table(x,paste0("res_", r, "_", c, ".txt"))}
res=apply(smoke[,c('Low','High')], 1, function(x) myf(x[1],x[2]))
This works fine.output res_51_43.txt .......
Now I just want to add the corresponding names from smoke$sit to output text files. desired output res_bit_51_43.txt .......
myf<- function(t,c,r){x=5*c+r
write.table(x,paste0("res_", t, r, "_", c, ".txt"))}
res=apply(smoke[,c('Low','High','sit')], 1, function(x) myf(x[1],x[2],x[3]))
I got this error:
Error in 5 * c : non-numeric argument to binary operator