[R] R ignores number only with a nine under 10000
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Mon Nov 21 18:10:40 CET 2011
1) "datamatrix" is not a defined term. I think you mean "data.frame".
2) you have not supplied any sample data, so your example is not reproducible.
3) All of the values in a vector (i.e. a column of a data.table must be of the same type, be that character or numeric (or anything else, such as factor). We cannot tell what data you have in your file, but if you are already trying to mix numeric and strings then the data are probably being imported as factors which act like numbers in some cases and as strings in others. You might need to look at the arguments for read.table to turn off conversion to factor.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
set <astareh at hotmail.com> wrote:
>Hello R users,
>
>I'm trying to replace numerical values in a datamatrix with strings. R
>does
>this except for numbers under 10000 starting with a 9 (eg 98, 970, 9504
>etc). This is really weird and I wondered whether someone had
>encountered
>such a problem or knows the solution. I'm using the next script:
>
>test_1 <- read.table("5+ref_151111clusters3.csv", header = TRUE, sep =
>",",
>colClasses = "numeric")
>test_1[test_1 > 94885 & test_1 <= 113835] = "KE3926OT"
>test_1[test_1 != 0 & test_1 <= 18954] = "I8456"
>test_1[test_1 > 75944 & test_1 <= 94885] = "KE3873"
>test_1[test_1 > 56951 & test_1 <= 75944] = "KE3870"
>test_1[test_1 > 37991 & test_1 <= 56951] = "Cyprus1"
>test_1[test_1 > 18954 & test_1 <= 37991] = "ref"
>write.table(test_1, file = "test_replace7.txt", quote = FALSE,
>sep="\t")
>
>Thanks,
>Set
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/R-ignores-number-only-with-a-nine-under-10000-tp4091936p4091936.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list