Search
 
SCRIPT & CODE EXAMPLE
 

R

how to create for loop through columns and count non na cells by group in r

library(dplyr)

d %>%
  group_by(ID) %>%
  summarise(across(Col1:Col3, ~ sum(!is.na(.x)), .names = "non-{.col}"))

# A tibble: 3 x 4
     ID `non-Col1` `non-Col2` `non-Col3`
  <dbl>      <int>      <int>      <int>
1     1          3          2          3
2     2          2          0          2
3     3          1          1          0
Comment

PREVIOUS NEXT
Code Example
R :: r as.numeric all columns except 
R :: How to remove rows with inf from a dataframe in R 
R :: How to extract the row with min or max values? in R 
R :: create list in r 
R :: reorder columns in r 
R :: order barplot ggplot2 by value 
R :: infinite in r 
R :: r for loop 
R :: read xlsx in r 
R :: r dplyr summarize multiple columns 
R :: convert a column to row names in r 
R :: Score pairs of records probabilistically in r 
R :: R construct a named list 
R :: select last child with class in r 
R :: How to use group_by inside a function? 
R :: add comma every 3 digits in r 
R :: r select column names starting with 
R :: how to get the r2 value in r 
Rust :: rust allow unused 
Rust :: how to read from stdin rust 
Rust :: linking with `link.exe` failed: exit code: 1189 
Rust :: actix web 
Rust :: optional arguments rust 
Rust :: closure type in rust 
Rust :: unwrap_or_else in rust 
Rust :: armanriazi•rust•error•E0308•mismatched types expected type parameter ``, found associated type 
Rust :: rust program name 
Rust :: rust closeure 
Rust :: trait in rust 
Lua :: roblox lua random number 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =