The problem here is incorrect subsetting of data.frame
as in effect when you execute b1temp[1, ]
you get only 1
number where the standard deviation is not defined. Which is the reason of getting NA
.
By default data.frame
data are organized by column, not by row. So to apply sd
to your data you should use subsetting for the columns bitemp[, 1]
.
Please see the code and simulation below:
b1temp <- data.frame(x = 1:10)
b1temp[1, ]
# [1] 1
mean(b1temp[1, ])
# [1] 1
sd(b1temp[1, ])
# [1] NA
sd(1)
# [1] NA
b1temp[1, ]
# [1] 1 2 3 4 5 6 7 8 9 10
sd(b1temp[, 1])
# [1] 3.02765