[R] data$variable=factor(....) <NA> <NA> <NA>

Dagmar Juranková dagmar.juranka at gmail.com
Sat Jul 11 21:21:19 CEST 2015


Hello everybody, I have a problem with R.


I uploaded a questionnaire saved as csv into R and I tried to test
independence between two variables.



data <- read.csv("C:/Users/Me/Desktop/data.csv")>   View(data)> df =
read.csv("C:/Users/Me/Desktop/data.csv")> ls()
[1] "df"     "data"> attributes(data$gender)
$levels
[1] " F" " M" "F"  "M"

$class
[1] "factor"


I changed my variable "gender" into a factor using:


data$gender=factor(data$gender, levels=c(1:2), labels= c( "F", "M"),
exclude= NA, nmax= NA).


Then I wrote data$gender and the only thing i got was:


[1] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
<NA> <NA> <NA> <NA> <NA> <NA>

[21] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
<NA> <NA> <NA> <NA> <NA> <NA>

[41] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
<NA> <NA> <NA> <NA> <NA> <NA>

[61] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>

Levels: F M


Does anybody know why?


-My csv doc in the column gender is filled out properly. (M=Male, F= Female)

-My imported dataset in R is complete (all values)


! I have done this with a different excel document and it worked out
without any problems. I am really clueless. I cant go further and compare
the variables and do t-tests without this working.


Could someone please help me out?

Thank you.

	[[alternative HTML version deleted]]



More information about the R-help mailing list