I have a text file dataset that I read as follows:

```
cancer1 <- read.table("cancer.txt", stringsAsFactors = FALSE, quote='', header=TRUE,sep='\t')

```

I then have to convert the class of the constituent values so that I can perform mathematical analyses on the df.

```
cancer<-apply(cancer1,2, as.numeric)

```

This introduces >9000 NA values into a "17980 X 598" df. Hence there are too many NA values to just simply use "na.omit" as that just removes all of the rows....

Hence my plan is to replace each NA in each row with the mean value of that row, my attempt is as follows:

```
for(i in rownames(cancer)){
     cancer2<-replace(cancer, is.na(cancer), mean(cancer[i,]))
 }

```

However this removes every row just like na.omit:

```
dim(cancer2)
 [1]   0 598

```

Can someone tell me how to replace each of the NA values with the mean of that row?