0

I want to study the gender difference and so I am attempting to use the R function but I don't know how to use it.

This is my script.

data<-read.csv(file.choose())
attach(data)
data

Subset

newdata <- subset(data, Gender=="1","2", select=Total)
rajah9
  • 11,645
  • 5
  • 44
  • 57
  • Hi RiyaShah. Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and how to give a [minimale reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). That way you can help others to help you! – dario Feb 27 '20 at 11:41
  • 1
    Do you need `subset(data, Gender %in% 1:2, select=Total)` ? – Ronak Shah Feb 27 '20 at 11:43
  • A few additional remarks: Try to avoid using `attach` [see here](https://stackoverflow.com/questions/10067680/why-is-it-not-advisable-to-use-attach-in-r-and-what-should-i-use-instead) for an explanation. Similarly there are better options for sub-setting data than `subset`, especially if used in functions. In your case `data[data$Gender %in% c("1", "2"), "Total"]` would probably work also. – dario Feb 27 '20 at 11:44
  • Thank you dario. i'll try it for sure! – RiyaShah Feb 28 '20 at 03:06

1 Answers1

0
data1 <- data[data$Gender=="1",] # data for gender "1"
data2 <- data[data$Gender=="2",] # data for gender "2"

For number of records in different gender:

data.gender <- data %>% group_by(Gender) %>% summarise(Count=n())
Jay
  • 1,181
  • 1
  • 9
  • 10