To be fair, Jordan, I think R has some optimizations so that the arguments
in some cases are NOT evaluated until needed. So only one or the other
choice ever gets evaluated for each row. My suggestion merely has
typographic implications and some aspects of clarity and minor amounts of
less memory a
Yes, that will halve the number of multiplications.
If you�re looking for such optimisations then you can also consider
ifelse(G=='male', 65L, 58L). That will definitely use less time & memory if WC
is integer, but the trade-offs are more complicated if WC is floating point.
Regards,
Jorgen Har
Just a minor point in the suggested solution:
df$LAP <- with(df, ifelse(G=='male', (WC-65)*TG, (WC-58)*TG))
since WC and TG are not conditional, would this be a slight improvement?
df$LAP <- with(df, TG*(WC - ifelse(G=='male', 65, 58)))
-Original Message-
From: R-help On Behalf Of Jo
Hi Jim,
Yes, that is exactly what I am trying to do. Once I get that, I want to
plot time series data.
Thank you very much Jim.
On Fri, Nov 3, 2023 at 11:58 PM jim holtman wrote:
> Is this what you are after?
>
> library(tidyverse)
>
>
> library(lubridate)
>
> input <- structure(list(StationNam
Is this what you are after?
library(tidyverse)
library(lubridate)
input <- structure(list(StationName = c("PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1
df$LAP <- with(df, ifelse(G=='male', (WC-65)*TG, (WC-58)*TG))
That will do both calculations and merge the two vectors appropriately. It will
use extra memory, but it should be much faster than a 'for' loop.
Regards,
Jorgen Harmse.
--
Message: 8
Date: Fri, 3 Nov 202
Cbind is not a very good tool for adding columns to a data frame. Either use
explicit column referencing like
dt1$x <- new_data_vector
but you do have to make sure the new data vector has the same number of values
and in the same order as the other data in dt1. The transition from multiple
rec
Well, something like:
LAP <- ifelse(gender =='male', (WC-65)*TG, (WC-58)*TG)
The exact code depends on whether your variables are in a data frame or
list or whatever, which you failed to specify. If so, ?with may be useful.
Cheers,
Bert
On Fri, Nov 3, 2023 at 3:43 AM Md. Kamruzzaman wrote:
It's still kind of weird; embedded 2-column data frames print differently than
1-column ones:
> d <- data.frame(a=1, b=I(data.frame(d=1,e=2)))
> d
a b.d b.e
1 1 1 2
> str(d)
'data.frame': 1 obs. of 2 variables:
$ a: num 1
$ b:Classes 'AsIs' and 'data.frame': 1 obs. of 2 variables:
Hello Everyone,
I have three variables: Waist circumference (WC), serum triglyceride (TG)
level and gender. Waist circumference and serum triglyceride is numeric and
gender (male and female) is categorical. From these three variables, I want
to calculate the "Lipid Accumulation Product (LAP) Index"
Hi,
I tried this:
# extract date from the time stamp
dt1 <- cbind(as.Date(dt$EndDate, format="%m/%d/%Y"), dt$EnergykWh)
head(dt1)
colnames(dt1) <- c("date", "EnergykWh")
and
my dt1 becomes these, the dates are replace by numbers.
dt1 <- cbind(as.Date(dt$EndDate, format="%m/%d/%Y"), dt$EnergykWh)
d
11 matches
Mail list logo