0

With this table below, can we transpose using rhandsontable. So where ever the user is residing in a place, then yes, or else No

df
User Places
A    fsdfsd
B    fsdfsd
C    fsdfsd
A    fsfgfd
B    fsfgfd

Expected output

User    fsdfsd  fsfgfd  Total Yes
A        Yes    Yes        2
B        Yes    Yes        2
C        Yes    No         1
Ric S
  • 9,073
  • 3
  • 25
  • 51
manish p
  • 177
  • 6

1 Answers1

1

A solution using dplyr and tidyr packages

library(dplyr)
library(tidyr)

df %>% 
  mutate(value = "Yes") %>% 
  pivot_wider(User, names_from = Places, values_from = value, values_fill = "No") %>% 
  rowwise() %>% 
  mutate(`Total Yes` = sum(c_across(-User) == "Yes"))

Output

# A tibble: 3 x 4
# Rowwise: 
#   User  fsdfsd fsfgfd `Total Yes`
#   <chr> <chr>  <chr>        <int>
# 1 A     Yes    Yes              2
# 2 B     Yes    Yes              2
# 3 C     Yes    No               1
Ric S
  • 9,073
  • 3
  • 25
  • 51