6
When I import a file .sav
i don’t want the <NA> character to appear in my mydata1
. I would like instead of NA to appear, for example, "Something else".
mydata = read.spss('mydata.sav', use.value.labels = TRUE, to.data.frame = TRUE,
max.value.labels = Inf, trim.factor.names = FALSE,
trim_values = FALSE, reencode = "UTF-8")
(mydata1<- mydata[10:20,25:31])
Q_16_O3 Q_16_O4 Q_16_O5 Q_16_O6 Q_16_O7 Q_16_O8 Q_16_O9
10 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
11 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
12 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
13 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
14 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
15 Trem <NA> <NA> <NA> <NA> <NA> <NA>
16 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
17 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
18 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
19 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
20 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
Putting the str
and the dput
str(mydata1)
'data.frame': 11 obs. of 7 variables:
$ Q_16_O3: Factor w/ 10 levels "Ônibus","Vans",..: NA NA NA NA NA 4 NA NA NA NA ...
$ Q_16_O4: Factor w/ 10 levels "Ônibus","Vans",..: NA NA NA NA NA NA NA NA NA NA ...
$ Q_16_O5: Factor w/ 10 levels "Ônibus","Vans",..: NA NA NA NA NA NA NA NA NA NA ...
$ Q_16_O6: Factor w/ 10 levels "Ônibus","Vans",..: NA NA NA NA NA NA NA NA NA NA ...
$ Q_16_O7: Factor w/ 10 levels "Ônibus","Vans",..: NA NA NA NA NA NA NA NA NA NA ...
$ Q_16_O8: Factor w/ 10 levels "Ônibus","Vans",..: NA NA NA NA NA NA NA NA NA NA ...
$ Q_16_O9: Factor w/ 10 levels "Ônibus","Vans",..: NA NA NA NA NA NA NA NA NA NA ...
dput(head(mydata1))
structure(list(Q_16_O3 = structure(c(NA, NA, NA, NA, NA, 4L), .Label = c("Ônibus",
"Vans", "Metrô", "Trem", "BRT", "Barca", "Catamarã", "Fretados",
"VLT/Monotrilho", "Lotação (micro-ônibus especial)"), class = "factor"),
Q_16_O4 = structure(c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = c("Ônibus",
"Vans", "Metrô", "Trem", "BRT", "Barca", "Catamarã", "Fretados",
"VLT/Monotrilho", "Lotação (micro-ônibus especial)"), class = "factor"),
Q_16_O5 = structure(c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = c("Ônibus",
"Vans", "Metrô", "Trem", "BRT", "Barca", "Catamarã", "Fretados",
"VLT/Monotrilho", "Lotação (micro-ônibus especial)"), class = "factor"),
Q_16_O6 = structure(c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = c("Ônibus",
"Vans", "Metrô", "Trem", "BRT", "Barca", "Catamarã", "Fretados",
"VLT/Monotrilho", "Lotação (micro-ônibus especial)"), class = "factor"),
Q_16_O7 = structure(c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = c("Ônibus",
"Vans", "Metrô", "Trem", "BRT", "Barca", "Catamarã", "Fretados",
"VLT/Monotrilho", "Lotação (micro-ônibus especial)"), class = "factor"),
Q_16_O8 = structure(c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = c("Ônibus",
"Vans", "Metrô", "Trem", "BRT", "Barca", "Catamarã", "Fretados",
"VLT/Monotrilho", "Lotação (micro-ônibus especial)"), class = "factor"),
Q_16_O9 = structure(c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = c("Ônibus",
"Vans", "Metrô", "Trem", "BRT", "Barca", "Catamarã", "Fretados",
"VLT/Monotrilho", "Lotação (microônibusespecial)"),class="factor")),.Names=c("Q_16_O3",
"Q_16_O4", "Q_16_O5", "Q_16_O6", "Q_16_O7", "Q_16_O8", "Q_16_O9"
), row.names = 10:15, class = "data.frame")
What technology you are using. Try to use the tags to indicate better what you are working on.
– Maniero
I don’t know much of r, but it seems if you do
> mydata[is.na(mydata)] <- 0
, in this case replaces<NA>
for0
, see if it helps: http://stackoverflow.com/questions/18562680/replacing-nas-with-0s-in-r-dataframe– abfurlan
Doesn’t work...
– orrillo
In fact, if it were only NA instead of <NA> it would work
– orrillo
Vasco, you could put the result of
str(mydata)
question? (and if possible the result of thedput(head(mydata))
It would make it easier to understand what’s going on.– Carlos Cinelli
Hi Carlos Cinelli. See if it looks good... Thank you
– orrillo
Cinelli, actually I want to do a "freq" in one of the rows of my new "mydata1"
– orrillo
Vasco, I think I understand your problem, I answered there, see if you answer, abs
– Carlos Cinelli