R vector numeric expression warning

Code_Infinity :

I created a simple vector in R to store the temperatures of 3 patients.

temperature <- c(98.1, 98.6, 101.4)

then later I tried to retrieve the temperature of the second and third patient.

temperature[2:3] [1] 98.6 101.4

While trying to retrieve all three values I succeeded but then got this warning from RStudio

temperature[1:2:3] [1] 98.1 98.6 101.4

Warning message: In 1:2:3 : numerical expression has 2 elements: only the first used

What does this warning mean?

narendra-choudhary :

The expression temperature[1:2:3] though is valid (valid in the sense that it will compile without errors) in R, but will give you same result as temperature[1:3].

R only uses the first and the last indices. So, temperature[1:3:4:5:3] is same as temperature[1:3].

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=390519&siteId=1