Relative Content

Tag Archive for rdplyrtidyverse

How to count the number of “No” ocurrencies across multiple columns in R [duplicate]

This question already has answers here: Compute row-wise counts in subsets of columns in dplyr (2 answers) Closed 15 days ago. I have a large dataset and I need to count the total occurrences of “no” across multiple columns. The dataset looks like this: id = c(1,2,3,4,5,6,7,8) trat = c(“a”,”b”,”a”,”b”,”a”,”b”,”a”,”b”) var1 = c(“no”,”no”,”no”,”no”,”yes”,NA,NA,”no”) var2 = […]

Attempting to calculate ratios in multiple columns in dataframe via a for loop

I’m using R to calculate simple ratios in columns and save those values in another table. The columns seen in the str included are every day in January and every hour of every day in January. For the purposes of this project, I have to calculate all of the hours of the month. I’m getting an appropriate table, but all the values are NA, so the logic or my attempt is failing somewhere and I’ve read all I can read. I’ve hit my limit on trying to find the issue and I need help.

Weighted mean per group with different weights per group using dplyr

I am attempting to modify my code below to a single pipeline using dplyr. I am calculating a weighted mean across two columns per year where each year has a different weighting. How can this been performed without explicitly splitting the dataset and then combining the results? Thanks