You want
y <- ifelse(x == 'a', 1,  2)

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
Tim Smith
Verzonden: donderdag 16 januari 2014 14:32
Aan: r
Onderwerp: [R] ifelse...

Hi,

Sorry for the newbie question! My code:

x <- 'a'
ifelse(x == 'a',y <- 1, y <- 2)
print(y)

Shouldn't this assign a value of 1? When I execute this I get:

> x <- 'a'
> ifelse(x == 'a',y <- 1, y <- 2)
[1] 1
> print(y)
[1] 2


Am I doing something really daft???

thanks!



> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] splines   parallel  stats     graphics  grDevices utils     datasets  
methods   base

other attached packages:
 [1] Biostrings_2.30.1     XVector_0.2.0         IRanges_1.20.6        
ggplot2_0.9.3.1       sda_1.3.2             fdrtool_1.2.11        corpcor_1.6.6
 [8] entropy_1.2.0         scatterplot3d_0.3-34  pdist_1.2             
hash_2.2.6            DAAG_1.18             multicore_0.1-7       
multtest_2.18.0 [15] XML_3.95-0.2          hgu133a.db_2.10.1     affy_1.40.0    
       genefilter_1.44.0     GOstats_2.28.0        graph_1.40.1          
Category_2.28.0 [22] GO.db_2.10.1          venneuler_1.1-0       rJava_0.9-6    
       colorRamps_2.3        RColorBrewer_1.0-5    sparcl_1.0.3          
gap_1.1-10 [29] plotrix_3.5-2         som_0.3-5             pvclust_1.2-2       
  lsr_0.3.1             compute.es_0.2-2      sm_2.2-5.3            
imputation_2.0.1 [36] locfit_1.5-9.1        TimeProjection_0.2.0  
Matrix_1.1-1.1        timeDate_3010.98      lubridate_1.3.3       gbm_2.1       
        lattice_0.20-24 [43] survival_2.37-4       RobustRankAggreg_1.1  
impute_1.36.0         reshape_0.8.4         plyr_1.8              zoo_1.7-10    
        data.table_1.8.10 [50] foreach_1.4.1         foreign_0.8-57        
languageR_1.4.1       pr!
 eprocessCore_1.24.0 gtools_3.1.1          BiocInstaller_1.12.0  
org.Hs.eg.db_2.10.1 [57] RSQLite_0.11.4        DBI_0.2-7             
AnnotationDbi_1.24.0  Biobase_2.22.0        BiocGenerics_0.8.0    biomaRt_2.18.0

loaded via a namespace (and not attached):
 [1] affyio_1.30.0         annotate_1.40.0       AnnotationForge_1.4.4 
codetools_0.2-8       colorspace_1.2-4      dichromat_2.0-0       digest_0.6.4
 [8] grid_3.0.2            GSEABase_1.24.0       gtable_0.1.2          
iterators_1.0.6       labeling_0.2          latticeExtra_0.6-26   MASS_7.3-29 
[15] munsell_0.4.2         proto_0.3-10          RBGL_1.38.0           
RCurl_1.95-4.1        reshape2_1.2.2        scales_0.2.3          stats4_3.0.2 
[22] stringr_0.6.2         tools_3.0.2           xtable_1.7-1          
zlibbioc_1.8.0

        [[alternative HTML version deleted]]

* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document.

______________________________________________
R-help@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.

Reply via email to