A BUG? of WITHIN function in R language

topic description

A BUG? of WITHIN function in R language

sources of topics and their own ideas

problems found when classifying with within function

related codes

doesn"t seem to show the correct R code, so I have to map it.

what result do you expect? What is the error message actually seen?

first time + b [b > 3000 & b < = 9999.9] <-"A"
second time + b [b > 3000 & b < = 10000.0] <-"A"
only increases 0.1, the classification can not get the correct result.
Let"s see if it is the BUG? of the WITHIN function in R language

.
Bug r
Mar.08,2022

The main reason for

is that the comparison operator of R is a little strange compared with other languages.


<strong>,f$bcharacter</strong>

<blockquote>f <- data.frame(a = c(1,2,3,4,5,6), b = c(4400,2220,3080,3140,0,1150))

f<br> a b<br>1 1 4400<br>2 2 2220<br>3 3 3080<br>4 4 3140<br>5 5 0<br>6 6 1150

f <- within(f,{

</blockquote> <ul> <li>b[b > 1000 & b <= 3000] <- "B"</li> <li> <li>})</li> </ul> <blockquote>f<br> a b<br>1 1 4400<br>2 2 B<br>3 3 3080<br>4 4 3140<br>5 5 0<br>6 6 B

summary(f)

</blockquote>
   a             b            

Min. : 1.00 Length:6
1st Qu.:2.25 Class: character
Median: 3.50 Mode: character
Mean: 3.50
3rd Qu.:4.75
Max. : 6.00

within (f, {
  • b [b > 3000 & b < = 10000.0] <-"A"
  • })
    a b

1 1 4400
22 B
3 3 3080
44 3140
550
6 6B

"4400" < = 10000.0
[1] FALSE

"4400" < = 9999.9
[1] TRUE

f <-data.frame (a = c (1,), b, 2, 3, 4, 5, 5,), b = c (4400, 2220, 3080, 3140, 050))

f
a b
11 4400
22 2220
3 3 3080
44 3140
5 50
6 6 1150

f <-within (f, {

  • b [b > 1000 & b < = 3000] <-1
  • })
f
a b
1 1 4400
221
3 3 3080
44 3140
550
6 61

summary (f)

   a              b       

Min. : 1.00 Min. : 0
1st Qu.:2.25 1st Qu.: 1
Median: 3.50Median: 1540
Mean: 3.50Mean: 1770
3rd Qu.:4.75 3rd Qu.:3125
Max. : 6.00 Max. : 4400

within (f, {
  • b [b > 3000 & b < = 10000.0] <-2
  • })
    a b

1 12
2 21
3 32
4 42
550
6 61

Menu