Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have 16 variables that are numeric, and I need to create an extra column that is YES (otherwise NO) when 3 or more variables out of those 16 have a value above 1015.
How could I do that?
Thanks
You can try with rowSums :
cols <- 1:16
df$res <- ifelse(rowSums(df[cols] > 1015, na.rm = TRUE) >= 3, 'Yes', 'No')
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 17 days ago.
Improve this question
I have a dataset with time, where the time intervals are 6 hours apart and I have a column of heaterstatus.
The dataset :
I would like to know the percentage of zero occurred in each day for heaterstatus. New to R, any suggestion will be helpful.
Not tested since you only provided data as an image, but this should do what you want:
library(dplyr)
dat %>%
group_by(day = as.Date(Time)) %>%
summarize(pct_0 = mean(HeaterStatus == 0))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
This is the following R code.
mutate(Loan_Status_delinquency = ifelse(EOM_Delinq_Bucket %in% c(1, 2, 3, 4), "Yes", "No"))
I want this to be convert into Python
Thanks in advance.
You can try
df['result'] = df.Loan_Status_delinquency.isin([1,2,3,4]).replace({ True : 'Yes', False : 'No'})
df[['new_columm']] = df.Loan_Status_delinquency.apply(lambda x: "Yes" if x in [1,2,3,4] else "No")
Will add a column new_column onto your pandas dataframe df. In the future please have a go and we can look at your attempt - it'll mean you have to come here less often!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have to create a "sum if" by column with multiple criteria.
I've tried this:
b <- DB.all %>% group_by(Family) %>% summarise(x)
But it doesn't work.
How can I do it?
Try this:
library(dplyr)
b <- DB.all %>% group_by(Family) %>% summarise(sum(x))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How is it possible to get rid of all NaN values and replace them by zero (0) in a complex function / whole R file?
I'm not sure about what you mean by a whole file/complex function, but depending on the data type you're storing the file with, it's pretty easy using is.na():
df <- data.frame(A = rep(1, 5), B = rep(1,5))
df$B[1] <- NA
df$A[3] <- NA
df[is.na(df)] <- 0
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Lets say I have a vector c(1,2,3,4,5,6,7,8,9) how can I get a print of just 1,3,and 5 ?
For a sample of n random elements from vector X you can use sample(x = X, size = 3, replace = FALSE). To get the ith element of X you simply use X[i].