Reputation: 489
I have a simple query. I am trying to get the standard deviation of each row between two columns in an array (n=2 for the length of the array; I know it's a small sample size)
It forms part of a longer code but simply:
data$i <- sd(data$x, data$y)^2 + (0.1)^2 / data$j
so my data would look like this:
x y
3 13
4 9
19 3
14 3
18 4
3 10
9 4
3 6
3 8
10 9
8 10
11 9
13 12
15 14
19 16
8 8
8 18
11 14
10 12
18 14
12 20
6 8
and, just using the sd()
, I would like to get this:
7.1
3.5
11.3
7.8
9.9
4.9
3.5
2.1
3.5
0.7
1.4
1.4
0.7
0.7
2.1
0.0
7.1
2.1
1.4
2.8
5.7
1.4
Upvotes: 1
Views: 5257
Reputation: 206243
To apply sd()
across the rows, you would use apply
apply(data[, c("x","y")],1,sd)
Upvotes: 4