R Program Version issue

53 Views Asked by At

Results are different in Version 3.6 & 4.1.

My R(3.6) code in the ubuntu server(18) is running well but the same code in ubuntu 20 R(4.1) is working very badly. look at this capture Issue with R Version

The purpose of this code is to normalize the column by dividing the sum.

Thank you all in advance.

1

There are 1 best solutions below

5
SamR On

Please don't post code as an image. It is also advised to post a reproducible example.

In any case, in your example on R 3.6, all_bins is a factor. However, in your R 4.1 example, all_bins is a character vector.

This is because of the change in R 4.0.0.:

R now uses a ‘⁠stringsAsFactors = FALSE⁠’ default, and hence by default no longer converts strings to factors in calls to data.frame() and read.table().

In order to reproduce the server behaviour on your local machine, when you read in bins in your local version of R, you need to add the argument stringsAsFactors = TRUE, e.g.:

bins <- read.csv("path/to/file", stringsAsFactors = TRUE)

This should solve this particular issue. However, you may run into other differences between R 3.6 and R 4.1 on different machines. I would recommend running the same version of R and packages on both machines, perhaps using renv, if you want to ensure the output is the same.