Re: [R] Can't compute row means of two columns of a dataframe.

2024-06-08 Thread Ebert,Timothy Aaron
Would this work? xxxz$Average20 <- (xxxz$Low20 + xxxz$High20)/2 I tried this earlier but it does not appear to have gone through. Tim -Original Message- From: R-help On Behalf Of avi.e.gr...@gmail.com Sent: Saturday, June 8, 2024 2:16 PM To: 'Sorkin, John' ; r-help@r-project.org

Re: [R] Can't compute row means of two columns of a dataframe.

2024-06-08 Thread Ebert,Timothy Aaron
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

Re: [R] Can't compute row means of two columns of a dataframe.

2024-06-08 Thread avi.e.gross
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: >

Re: [R] Can't compute row means of two columns of a dataframe.

2024-06-08 Thread Bert Gunter
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

Re: [R] Can't compute row means of two columns of a dataframe.

2024-06-08 Thread Bert Gunter
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.

[R] Can't compute row means of two columns of a dataframe.

2024-06-08 Thread Sorkin, John
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,