r-project.org
Subject: Re: [R] Can't compute row means of two columns of a dataframe.
[External Email]
John,
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 functi
Can this problem be made more direct?
xxxz$Average.20 <- (xxxz$Low20 + xxxz$High20)/2
That is literally the mean of two columns. Functions can be useful if there
will be more columns, but with just two this seems easier.
I will point out that the average daily temperature based on the midpoint
John,
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:
> rowMean
Incidentally, FWIW, for means, rowMeans() is a lot faster:
xxxz$av20 <- rowMeans(xxxz[,c("Low20","High20")])
Bert
On Sat, Jun 8, 2024 at 10:47 AM Bert Gunter wrote:
> Use apply(), not by().
>
> xxxz$av20 <- apply(xxxz[,c("Low20","High20")],1, mean)
>
> -- Bert
>
> On Sat, Jun 8, 2024 at 10:3
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
wrote:
> 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.
5 matches
Mail list logo