Re: [R] help with checking out-of-range values in each column in data frame

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 28 Jan 2008 08:24:35 -0500

Try:

transform(data, f1 = factor(f1, levels = 1:5), f4 = factor(f4, 1:3))

On Jan 28, 2008 8:12 AM, Tom Cohen <tom.cohen78_at_yahoo.se> wrote:
> Dear list,
>
> I have following data, where I want to check if any value in each
> column is out of range. For example, column "f1" can only take values
> 1-5, so if any values less than 1 or > 5 will be
> defined as missing value (i.e. NA), column "f4" can only take values
> of 1-3 and any values that are outside this interval will be
> considered as missing values. The below data is a subset of a big survey
> sample and I want to create an automatic procedure to check if all particpants
> gave a reasonable answer. How can I do this in R and also replace the empty
> values with NA?
>
> > dat
> id f1 f2 f3 f4 f5 f6 f7 f8 f9 f10
> 1 1 5 3 1 1 1 1 2 1 1 1
> 2 2 5 5 1 1 1 1 2 1 1 2
> 3 3 3 4 1 1 1 1 2 1 1 1
> 4 4 5 5 1 1 1 1 1 1 1 1
> 5 5 4 3 2 1 2 2 1 2 3
> 6 6 4 4 1 2 2 1 2 1 1 1
> 7 7 4 4 1 1 1 2 3 2 2 2
> 8 8 4 5 2 2 2 2 2 2 2 2
> 9 9 4 4 2 3 3 3 3 3 3 3
> 10 10 4 3 1 2 3 1 2 1 2 3
> 11 11 2 5 1 1 2 1 3 1 1 2
> 12 12 4 3 1 2 3 3 3 3 2 3
> 13 13 5 5 1 1 1 1 2 1 1 2
> 14 14 5 3 3 3 3 2 1 3 1 1
> 15 15 4 3 1 1 1 2 2 2 1 2
> 16 16 3 2 2 3 2 3 3 2 2 3
> 17 17 4 5 1 1 1 1 2 1 1 1
> 18 18 3 3 2 2 3 2 3 2 3 3
> 19 19 4 4 1 2 2 2 3 2 3 3
> 20 20 4 4 1 2 3 3 3 2 3 3
>
> Thanks in advance,
> Tom
>
>
> ---------------------------------
> Går det långsamt? Skaffa dig en snabbare bredbandsuppkoppling.
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 28 Jan 2008 - 13:35:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Jan 2008 - 14:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive