Hello, 

I have a table in R which consists of 70k rows and 37 columns. Lot of cells have **"./."**  which I want to modify and make it as **"ab"** . I tried to use `gsub()` but it does not give me the required output. 

I used :

    file <- gsub("./.","ab",file)

I want the change to happen throughout the file.
Is there any other way with which I can modify it? Thanks in advance.


Input: 
Eg:

    S.no chr pos gene_name S1 S2 S3
    1        1    1290    X            ./.   1/1  ./.
    2        1     5822    Y           0/1   ./.   ./.

Output 

 

    S.no chr pos gene_name S1 S2 S3
        1        1    1290    X            ab   1/1  ab
        2        1     5822    Y           0/1   ab   ab

It can be either ab or NA


Try to use fixed match:

    file <- gsub("./.","ab",file, fixed = TRUE)

Or 

    file[ file == "./." ] <- "ab"

-----------

**Edit:** Using example data provided by OP.

    # example input data
    df1 <- read.table(text = "
    S.no chr pos gene_name S1 S2 S3
    1        1    1290    X            ./.   1/1  ./.
    2        1     5822    Y           0/1   ./.   ./.", header = TRUE, stringsAsFactors = FALSE)
    
    df1
    #   S.no chr  pos gene_name  S1  S2 S3
    # 1    1   1 1290         X  ab 1/1 ab
    # 2    2   1 5822         Y 0/1  ab ab
    
    df1[, c("S1", "S2", "S3")][ df1[, c("S1", "S2", "S3")] == "./." ] <- "ab"
    df1
    #   S.no chr  pos gene_name  S1  S2 S3
    # 1    1   1 1290         X  ab 1/1 ab
    # 2    2   1 5822         Y 0/1  ab ab

