Re: [R] [EXTERNAL] RE: I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-03 Thread avi.e.gross
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

Re: [R] [EXTERNAL] RE: I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-03 Thread Jorgen Harmse via R-help
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

Re: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-03 Thread avi.e.gross
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

Re: [R] Sum data according to date in sequence

2023-11-03 Thread roslinazairimah zakaria
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 <-

Re: [R] Sum data according to date in sequence

2023-11-03 Thread jim holtman
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

Re: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-03 Thread Jorgen Harmse via R-help
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

Re: [R] Sum data according to date in sequence

2023-11-03 Thread Jeff Newmiller via R-help
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

Re: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-03 Thread Bert Gunter
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:

Re: [R] Bug in print for data frames?

2023-11-03 Thread peter dalgaard
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:

[R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-03 Thread Md. Kamruzzaman
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)

Re: [R] Sum data according to date in sequence

2023-11-03 Thread roslinazairimah zakaria
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)