Dihan
Dihan

Reputation: 311

R output format with word in inside

I=2 
J=2 
A=c(1,1)

I want to create a function with the above arguments which will produce an output in this format:

cell (1,1) --> support set = (0,0)
cell (1,2) --> support set = (0,1)
cell (2,1) --> support set = (1,0)
cell (2,2) --> support set = (1,1)

Here if the first element of cell matches with the first element of A, output 0, else 1. Same for the second element. My question is how to create this kind of output format with words in r? I have no clue.

Upvotes: 0

Views: 26

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173858

Are you looking for something like this?

cell_support <- function(I, J, A)
{
  cat("cell(", I, ", ", J, ") --> support set = (", 
      1 - (I == A[1]), ", ", 1 - (J == A[2]), ")\n", sep = "")
}

cell_support(I = 1, J = 2, A = c(2, 2))
#> cell(1, 2) --> support set = (1, 0)

cell_support(I = 2, J = 1, A = c(1, 1))
#> cell(2, 1) --> support set = (1, 0)

Upvotes: 1

Related Questions