'jamovi compute new variable total as sumif cols have text?

working in jamovi. I have 10 cols col1 through col10 that either have text or are blank. I want to compute a new variable total_col that simply counts how many cols contain text. Is this a sumif? what would it look like in the jamovi compute panel?



Solution 1:[1]

The Jamovi module Rj allows you to execute R code. The following code will return the number of columns with a class that can contain text (character and factor):

sum(sapply(iris, ## replace "iris" with the name of your data set
           function(VAR) class(VAR) %in% c("character", "factor")))

Note that in R the class is fixed per column of a dataframe, so the number of cells which can contain text will be the same for all rows. If you want to have these identical entries in a separate column though, this should* do:

iris$cellcount_text <- sum(sapply(iris, ## replace "iris" as above
           function(VAR) class(VAR) %in% c("character", "factor")))

* Not tested, only found that there's a Jamovi module for using R code and supplied the R code (hoping that you can address the underlying data with the name you saved them under).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 I_O