Re: [R] "missings=function(x) x[x==998|x==999]<-NA" doesn't work...

2014-09-18 Thread Ben Tupper
Hi, On Sep 18, 2014, at 10:13 AM, Doreen Mueller wrote: > Hi! > > I want to have a function that assigns NAs to certain values of my > variable "var" in the dataset "d". This doesn't work: > >> missings=function(x) x[x==998|x==999]<-NA >> missings(d$var) >> table(d$var, useNA="always") > >

Re: [R] "missings=function(x) x[x==998|x==999]<-NA" doesn't work...

2014-09-18 Thread Sarah Goslee
You need to assign the output of missings() to something. For that matter, missings() needs some output. d <- data.frame(a=1:5, b=6:10, var=c(1, 1, 998, 999, 2)) missings <- function(x) { x[x==998|x==999]<-NA x } d$var <- missings(d$var) > d a b var 1 1 6 1 2 2 7 1 3 3 8 NA

[R] "missings=function(x) x[x==998|x==999]<-NA" doesn't work...

2014-09-18 Thread Doreen Mueller
Hi! I want to have a function that assigns NAs to certain values of my variable "var" in the dataset "d". This doesn't work: > missings=function(x) x[x==998|x==999]<-NA > missings(d$var) > table(d$var, useNA="always") 0 1 999 220 752 321 5264 I don't get any error messages, but

Re: [R] missings

2009-03-05 Thread jim holtman
This seems to work fine without the na.strings. Can you include the data that you were reading: > x <- read.table(textConnection("1,2,3,4 + 5,,6,NA + ,7,NA,8 + ,,NA,9"), sep=',') > closeAllConnections() > x V1 V2 V3 V4 1 1 2 3 4 2 5 NA 6 NA 3 NA 7 NA 8 4 NA NA NA 9 On Thu, Mar 5, 200

[R] missings

2009-03-05 Thread kayj
I have a file where the missings are coded as NA or blank. how can I tell R to read the data set and to consider the missings NA or a blank. I tried the following data<-read.table("data.txt", sep='\t', header=T, na.strings=c("NA","")) is it correct? I am new to R and I am not sure if R is con