Simple question about Vector
1
0
Entering edit mode
Guest User ★ 13k
@guest-user-4897
Last seen 9.6 years ago
Hello I'm new at bioconductor and I have a very simple and stupid question, but I couldn undertand how to do that. I have a vector with a column with negative numbers(double). I want to change all negative to positive. I then made a function: ----------------------------- function(number){ if(number < 0){ number <- number * -1 } return(number) } ----------------------------- then I run > bed[12] <- arruma(bed[,11]) I got this error Warning message: In if (number < 0) { : the condition has length > 1 and only the first element will be used What happen is that all negative became positive and all positive became negative. Does enybody know what I'm doing wrong? thanks and best regards -- output of sessionInfo(): > sessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.2 -- Sent via the guest posting facility at bioconductor.org.
• 888 views
ADD COMMENT
0
Entering edit mode
Mark Cowley ▴ 910
@mark-cowley-2951
Last seen 9.6 years ago
Hi Thiago, have a look at ?ifelse or ?abs cheers, Mark On 26/02/2013, at 10:46 PM, "Thiago [guest]" <guest at="" bioconductor.org=""> wrote: > > Hello > > I'm new at bioconductor and I have a very simple and stupid question, but I couldn undertand how to do that. > > I have a vector with a column with negative numbers(double). I want to change all negative to positive. > I then made a function: > ----------------------------- > function(number){ > if(number < 0){ > number <- number * -1 > } > return(number) > } > ----------------------------- > then I run >> bed[12] <- arruma(bed[,11]) > > I got this error > > Warning message: > In if (number < 0) { : > the condition has length > 1 and only the first element will be used > > What happen is that all negative became positive and all positive became negative. > > Does enybody know what I'm doing wrong? > > thanks and best regards > > -- output of sessionInfo(): > >> sessionInfo() > R version 2.15.2 (2012-10-26) > Platform: x86_64-w64-mingw32/x64 (64-bit) > > locale: > [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] tools_2.15.2 > > -- > Sent via the guest posting facility at bioconductor.org. > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD COMMENT
0
Entering edit mode
Hello Mark Thanks a lot for the help, you was right it worked now with this command bed[12] <- ifelse(bed[11] < 0, abs(bed[11]*-1),bed[11]) thanks Thiago > Hi Thiago, > have a look at ?ifelse or ?abs > cheers, > Mark > > On 26/02/2013, at 10:46 PM, "Thiago [guest]" <guest at="" bioconductor.org=""> > wrote: > >> >> Hello >> >> I'm new at bioconductor and I have a very simple and stupid question, >> but I couldn undertand how to do that. >> >> I have a vector with a column with negative numbers(double). I want to >> change all negative to positive. >> I then made a function: >> ----------------------------- >> function(number){ >> if(number < 0){ >> number <- number * -1 >> } >> return(number) >> } >> ----------------------------- >> then I run >>> bed[12] <- arruma(bed[,11]) >> >> I got this error >> >> Warning message: >> In if (number < 0) { : >> the condition has length > 1 and only the first element will be used >> >> What happen is that all negative became positive and all positive >> became negative. >> >> Does enybody know what I'm doing wrong? >> >> thanks and best regards >> >> -- output of sessionInfo(): >> >>> sessionInfo() >> R version 2.15.2 (2012-10-26) >> Platform: x86_64-w64-mingw32/x64 (64-bit) >> >> locale: >> [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United >> States.1252 >> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C >> [5] LC_TIME=English_United States.1252 >> >> attached base packages: >> [1] stats graphics grDevices utils datasets methods base >> >> loaded via a namespace (and not attached): >> [1] tools_2.15.2 >> >> -- >> Sent via the guest posting facility at bioconductor.org. >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor > --
ADD REPLY

Login before adding your answer.

Traffic: 1040 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6