Displaying 3 results from an estimated 3 matches for "xxxz".
Did you mean:
xxx
2024 Jun 08
3
Can't compute row means of two columns of a dataframe.
I have a data frame with three columns, TotalInches, Low20, High20. For each row of the dataset, I am trying to compute the mean of Low20 and High20.
xxxz <- structure(list(TotalInches =
c(58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76), Low20 = c(84, 87,
90, 93, 96, 99, 102, 106, 109, 112, 116, 119, 122, 126, 129,
133, 137, 141, 144), High20...
2024 Jun 08
1
Can't compute row means of two columns of a dataframe.
...,
Maybe you can clarify what you want the output to look like. It took me a
while to realize what you may want as it is NOT properly described as
wanting rowsums.
There is a standard function called rowMeans() that probably does what you
want if you want the mean of all rows as in:
> rowMeans(xxxz)
[1] 84.33333 87.00000 89.66667 92.33333 95.00000 97.66667 100.33333
103.66667 106.33333 109.00000 112.33333 115.00000
[13] 118.00000 121.33333 124.00000 127.33333 130.66667 134.00000 137.00000
It does not add the means to the original data.frame if you wanted it there
but that is easy enou...
2024 Jun 08
1
Can't compute row means of two columns of a dataframe.
Use apply(), not by().
xxxz$av20 <- apply(xxxz[,c("Low20","High20")],1, mean)
-- Bert
On Sat, Jun 8, 2024 at 10:38?AM Sorkin, John <jsorkin at som.umaryland.edu>
wrote:
> I have a data frame with three columns, TotalInches, Low20, High20. For
> each row of the dataset, I am trying to comp...