Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

Factors to calculate total number of values [closed]

$
0
0

Write an R script to define a new character vector gender that is populated with “male” for the first 20 elements, and “female” for the next 30 elements. Use factors to quickly and efficiently calculate a total number of values in each gender category.

I created a dataset, but how I can use factor to calculate the number of elements?

I know only how to use table in this situation but I need a factor.

male <- c(length = 20)
male[1:20] <- "male"

female <-c(length=30)
female[1:30] <- "female"

gender=c(male,female)
factor(gender)
#out
#length                                                                                            
#male   male   male   male   male   male   male   male   male   male   male   male   male   male 
#length                                                  
#male   male   male   male   male   male female female female female female female female female 
#
#female female female female female female female female female female female female female female 
#
#female female female female female female female female 
#Levels: female male

Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>