Hi:

Strictly a guess, but the following might be helpful. The call below
assumes that the referent data frame is test1, which consists of a
single column named x. Modify as appropriate.

test_lab <- with(test1, cut(x, c(0, 18954, 37791, 56951, 75944, 84885, 113835),
                 labels = c('I8456', 'ref', 'Cyprus1', 'KE3870', 'KE3873',
                            'KE3926OT')))

cut() creates a factor from a numeric variable. The second argument
consists of the cut points and the third argument generates the labels
to be associated with values falling between the cut points. See ?cut
for more details, and pay attention to the options.

The object test_lab is a vector external to test1; if you want it to
be a column of test1, then add it to the data frame in one of the
usual ways.

HTH,
Dennis

On Mon, Nov 21, 2011 at 7:42 AM, set <asta...@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@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.
>

______________________________________________
R-help@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.

Reply via email to