> setwd("D:\\R data\\") > Book1 <- read.table(file = "Book1.txt", header = TRUE) > Book1 cre gender 1 45 male 2 28 male 3 23 male 4 49 male 5 32 male 6 42 male 7 30 male 8 40 male 9 47 male 10 24 male 11 34 female 12 47 female 13 38 female 14 42 female 15 26 female 16 27 female 17 21 female 18 41 female 19 48 female 20 45 female > t.test(cre~gender, var.eq =TRUE) Error in eval(predvars, data, env) : object 'cre' not found
In your t-test function call, R isn't sure where to find your
gender vectors. These are in the
Book1 data frame. To access a column in a data.frame in R, use the
$ extract operator.
t.test(Book1$cre ~ Book1$gender, var.eq =TRUE)
For a nice intro into R for Data Science, check out Garrett and Hadley's book
It was so helpful.....Although I am working with SPSS for a long period of time, R is new to me
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If your problem is solved, can you please mark this response as a solution? I fyou don't know how, please see here: FAQ: How do I mark a solution?.
An equivalent way of doing this to avoid specifying the data frame name multiple times is the
t.test(cre ~ gender, Book1, var.eq =TRUE)