Ester Silva - 1 year ago 51

R Question

I have the following code in R which give the following result.

`[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]`

[1,] 1.0 2.0 3.0 4.0 10.0 3.700000e+01 NA NA

[2,] -1.0 -1.0 -1.0 -1.0 -1.0 -8.987342e-01 -5.898734e+00 NA

[3,] 549492.9 217514.1 732960.6 506807.3 113711.8 1.393393e+05 2.259826e+06 NA

[4,] 1.0 2.0 3.0 4.0 10.0 2.200000e+01 3.700000e+01 NA

[5,] -1.0 -1.0 -1.0 -1.0 -1.0 -8.846154e-01 -8.987342e-01 -6.78335

[6,] 549492.9 217514.1 732960.6 506807.3 113711.8 2.376512e+05 1.393393e+05 2497477.34198

The problem is the result are not in my desired format. I mean, the first and the forths row should be int (a number between 1 and 59). The second and the fifth rows have to be presented in the format of the (-1 and 0 or a small float and not as a

`-8.987342e-01`

`2.376512e+05`

Any idea how I can solve it?

Thanks

Code:

`Time_Score_Estimation <- function(Paths) {`

Result<-c()

for (i in 1: nrow(Paths))

{

ROW <- matrix(nrow=2,ncol=ncol(Paths))

for (j in 1:length(Paths[i,][!is.na(Paths[i,])]))

{

LO <- Paths[i,j]

ROW[1,j] <- mean(LTRS.Transaction[which(LTRS.Transaction[,8] == LO),5])

ROW[2,j] <- mean(LTRS.Transaction[which(LTRS.Transaction[,8] == LO),6])

}

ROW[1,j+1] <- sum(ROW[1,][!is.na(ROW[1,])])

ROW[2,j+1] <- sum(ROW[2,][!is.na(ROW[2,])])

Result<- rbind(Result,Paths[i,],ROW)

}

return(Result)

}

Answer Source

See the answer here on changing the scientific notation setting in R Force R not to use exponential notation (e.g. e+10)?

To never see scientific notation use

```
options(scipen=999)
```