OT: Your signature [Bioanalytics]
x=c("Foo", "Bar")
b=data.frame(x)
typeof(b[,1]) ##aha, integer?
b[,1]+1 ##then let me add 1
![[image]](img/uploaded/image7.gif)
x <- c("Foo", "Bar")
is.character(x)
[1] TRUE
b <- data.frame(x)
is.character(b)
[1] FALSE
is.data.frame(b)
[1] TRUE
print(b)
x
1 Foo
2 Bar
So far, so good. What else?
str(b)
'data.frame': 2 obs. of 1 variable:
$ x: Factor w/ 2 levels "Bar","Foo": 2 1
Implicitly you are using the default of data.frame()
like here:
c <- data.frame(x, stringsAsFactors=TRUE)
Check #1
identical(c, b)
[1] TRUE
Check #2
c == b
x
[1,] TRUE
[2,] TRUE
See the point?
typeof(b[, 1]) ##aha, integer?
[1] "integer"
Correct. Factors are always coded as integers internally.
Check #3
is.factor(b[, 1])
[1] TRUE
Note also the output of str(b)
above where factors are given in lexical order.
However, since we defined x <- c("Foo", "Bar")
, "Bar"
gets the level 2
and "Foo"
the level 1
in b
.
b[, 1]+1 ##then let me add 1
[1] NA NA
Warning message:
In Ops.factor(b[, 1], 1) : ‘+’ not meaningful for factors
Well roared, lion!
On the other hand:
d <- data.frame(x, stringsAsFactors=FALSE)
print(d)
x
1 Foo
2 Bar
str(d)
'data.frame': 2 obs. of 1 variable:
$ x: chr "Foo" "Bar"
typeof(c[, 1])
[1] "character"
Is this what you expected?
d[, 1]+1
Error in c[, 1] + 1 : non-numeric argument to binary operator
Sure. Rubbish in, rubbish out.
Personally I prefer a straight error over a warning producing NAs.
![Cool! :cool:](https://static.bebac.at/img/smilies/cool.gif)
Dif-tor heh smusma 🖖🏼 Довге життя Україна!
![[image]](https://static.bebac.at/pics/Blue_and_yellow_ribbon_UA.png)
Helmut Schütz
![[image]](https://static.bebac.at/img/CC by.png)
The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
Complete thread:
- importance of bioanalytical validation averroes1304 2019-03-27 11:55 [Bioanalytics]
- importance of bioanalytical validation ElMaestro 2019-03-27 12:08
- OT: Your signatureHelmut 2019-03-27 14:41
- OT: Correct as often ElMaestro 2019-03-27 15:35
- OT: Nerds chatting Helmut 2019-03-27 18:48
- OT: Nerds chatting nobody 2019-03-27 19:01
- OT: Nerds chatting Helmut 2019-03-27 19:16
- OT: Nerds chatting nobody 2019-03-27 19:38
- OT: Nerds chatting Shuanghe 2019-03-28 13:59
- OT: Nerds chatting Helmut 2019-03-27 19:16
- OT: Nerds chatting ElMaestro 2019-03-27 22:07
- OT: Nerds chatting Ohlbe 2019-03-28 10:28
- OT: Nerds chatting nobody 2019-03-28 11:14
- OT: Nerds chatting Ohlbe 2019-03-28 10:28
- OT: Nerds chatting nobody 2019-03-27 19:01
- OT: Nerds chatting Helmut 2019-03-27 18:48
- OT: Correct as often ElMaestro 2019-03-27 15:35
- OT: Your signatureHelmut 2019-03-27 14:41
- importance of bioanalytical validation ElMaestro 2019-03-27 12:08