[R] TRUE/FALSE as numeric values

2007-02-23 Thread Thomas Preuth
Hello,

I want to select in a column of a dataframe all numbers smaller than a 
value x
but when I type in test-(RSF_EU$AREA=x) I receiv as answer:
  test
 [1]  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE 
FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[18]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  
TRUE  TRUE FALSE  TRUE  TRUE  TRUE
[35] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE FALSE  
TRUE  TRUE FALSE FALSE  TRUE FALSE
[52]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE

How can i get the values smaller than x and not the TRUE/FALSE reply?

Thanks in advance,
Thomas

__
R-help@stat.math.ethz.ch 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.


Re: [R] TRUE/FALSE as numeric values

2007-02-23 Thread Ranjan Maitra
On Fri, 23 Feb 2007 14:38:56 +0100 Thomas Preuth [EMAIL PROTECTED] wrote:

 Hello,
 
 I want to select in a column of a dataframe all numbers smaller than a 
 value x
 but when I type in test-(RSF_EU$AREA=x) I receiv as answer:
   test
  [1]  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE 
 FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 [18]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  
 TRUE  TRUE FALSE  TRUE  TRUE  TRUE
 [35] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE FALSE  
 TRUE  TRUE FALSE FALSE  TRUE FALSE
 [52]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE
 
 How can i get the values smaller than x and not the TRUE/FALSE reply?

if the dataframe is called RSF_EU, and you want the entire dataframe for those 
rows, then 

RSF_EU [ (RSF_EU$AREA = x ), ]

if you want to get only that column vector and nothing else

RSF_EU$AREA [ ( RSF_EU$AREA = x ) ]

Such concepts are very well-explained in An Introduction to R which you would 
benefit by reading at the earliest.

Ranjan


 Thanks in advance,
 Thomas
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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.


Re: [R] TRUE/FALSE as numeric values

2007-02-23 Thread Henrique Dallazuanna
You can also:

test - RSF_EU[which(RSF_EU$AREA=x),]

On 23/02/07, Thomas Preuth [EMAIL PROTECTED] wrote:

 Hello,

 I want to select in a column of a dataframe all numbers smaller than a
 value x
 but when I type in test-(RSF_EU$AREA=x) I receiv as answer:
  test
 [1]  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE
 FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 [18]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 TRUE  TRUE FALSE  TRUE  TRUE  TRUE
 [35] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE FALSE
 TRUE  TRUE FALSE FALSE  TRUE FALSE
 [52]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE

 How can i get the values smaller than x and not the TRUE/FALSE reply?

 Thanks in advance,
 Thomas

 __
 R-help@stat.math.ethz.ch 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.




-- 
Henrique Dallazuanna
Curitiba-ParanĂ¡
Brasil

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


Re: [R] TRUE/FALSE as numeric values

2007-02-23 Thread ONKELINX, Thierry
RSF_EU$AREA[RSF_EU$AREA=x]




ir. Thierry Onkelinx

Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest

Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance

Gaverstraat 4

9500 Geraardsbergen

Belgium

tel. + 32 54/436 185

[EMAIL PROTECTED]

www.inbo.be 

 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt

A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

 -Oorspronkelijk bericht-
 Van: [EMAIL PROTECTED] [mailto:r-help-
 [EMAIL PROTECTED] Namens Thomas Preuth
 Verzonden: vrijdag 23 februari 2007 14:39
 Aan: r-help@stat.math.ethz.ch
 Onderwerp: [R] TRUE/FALSE as numeric values
 
 Hello,
 
 I want to select in a column of a dataframe all numbers smaller than a
 value x
 but when I type in test-(RSF_EU$AREA=x) I receiv as answer:
   test
  [1]  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE
 FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 [18]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 TRUE  TRUE FALSE  TRUE  TRUE  TRUE
 [35] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE FALSE
 TRUE  TRUE FALSE FALSE  TRUE FALSE
 [52]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE
 
 How can i get the values smaller than x and not the TRUE/FALSE reply?
 
 Thanks in advance,
 Thomas
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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.


Re: [R] TRUE/FALSE as numeric values

2007-02-23 Thread Gavin Simpson
On Fri, 2007-02-23 at 14:38 +0100, Thomas Preuth wrote:
 Hello,
 
 I want to select in a column of a dataframe all numbers smaller than a 
 value x
 but when I type in test-(RSF_EU$AREA=x) I receiv as answer:
   test
  [1]  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE 
 FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 [18]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  
 TRUE  TRUE FALSE  TRUE  TRUE  TRUE
 [35] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE FALSE  
 TRUE  TRUE FALSE FALSE  TRUE FALSE
 [52]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE
 
 How can i get the values smaller than x and not the TRUE/FALSE reply?
 
 Thanks in advance,
 Thomas

You need to subset your object based on the results you achieved above.
What you did was only half the job. See this example, with a number of
ways to get what you want:

## some dummy data to work with
dat - 10 * runif(100)
dat - data.frame(AREA = dat, FOO = dat + rnorm(100))

## select values of AREA less than mean AREA
mn - mean(dat$AREA)
want1 - with(dat, AREA[AREA = mn])
## or
want2 - dat$AREA[dat$AREA = mn]
## or
want3 - subset(dat$AREA, dat$AREA = mn)
## or
want4 - subset(dat, AREA = mn)$AREA
## check they all do same thing
all.equal(want1, want2, want3, want4) ## TRUE

want2 is closest to how you tried to do it:

dat$AREA[dat$AREA = mn]
 ^^
Notice that you only did the inner bit marked, which as you found
returns TRUE/FALSE depending on whether that element of AREA met the
criterion of being less than or equal to your x. This information is
used to select elements from AREA using the subsetting functions for
objects.

HTH

G
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@stat.math.ethz.ch 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.


Re: [R] TRUE/FALSE as numeric values

2007-02-23 Thread Prof Brian Ripley
It is inefficient to use which() rather than a logical index, since you 
allocate two numeric index vectors (one the length of the original 
vector) and use an interpreted function rather than optimized C code.
Also, in this usage which() handles NAs incorrectly.

I think the clearest answer is probably

with(RSF_EU, AREA[AREA = x])

On Fri, 23 Feb 2007, Henrique Dallazuanna wrote:

 You can also:

 test - RSF_EU[which(RSF_EU$AREA=x),]

 On 23/02/07, Thomas Preuth [EMAIL PROTECTED] wrote:

 Hello,

 I want to select in a column of a dataframe all numbers smaller than a
 value x
 but when I type in test-(RSF_EU$AREA=x) I receiv as answer:
 test
 [1]  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE
 FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 [18]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
 TRUE  TRUE FALSE  TRUE  TRUE  TRUE
 [35] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE FALSE
 TRUE  TRUE FALSE FALSE  TRUE FALSE
 [52]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE

 How can i get the values smaller than x and not the TRUE/FALSE reply?

 Thanks in advance,
 Thomas

 __
 R-help@stat.math.ethz.ch 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.






-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch 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.