Displaying 20 results from an estimated 50000 matches similar to: "format integer numbers with leading 0"
2018 Jan 04
2
format integer numbers with leading 0
Dear R-er,
I would like format integer number as characters with leading 0 for a
fixed width, for example:
1 shoud be "01"
2 shoud be "02"
20 should be "20"
Now I use:
x <- c(1, 2, 20)
gsub(" ", "0", format(x, width=2))
But I suspect more elegant way could be done directly with format
options, but I don't find.
Thanks a lot
Marc
2011 Nov 29
2
format numbers without leading or trailing 0s
A simple question, but I can't find something to do what I want:
Given: a vector of numbers, like
lambda <- c(0, 0.005, 0.01, 0.02, 0.04, 0.08)
Desired: format them in minimal space for use as plot labels, ie,
without leading or tailing 0s. For this example:
lambdaf <- c("0", .005", ".01", ".02", ".04", ".08")
--
Michael
2011 Apr 29
1
regular expression in gsub() for strings with leading backslash
Hello,
Can anyone help on gsub() in R? I have a string like something below, and
wanted to delete all the strings with leading backslash, including "\xa0On",
"\023, "\xab", and many others. How should I write a regular expression
pattern in gsub()? I don't care how many characters following backslash.
txt <- "Is This Thing\xa0On? http://bit.ly/jAbKem
2009 Jan 25
1
strip leading 0's
Dear all,
Is there a simple way to strip the leading "0"'s from R output? For example,
I want
Data <- data.frame(x=rnorm(10), y=x*rnorm(10), z = x+y+rnorm(10))
cor(Data)
to give me
x y z
x 1.0000000 -.1038904 -.3737842
y -.1038904 1.0000000 .4414706
z -.3737842 .4414706 1.0000000
Several of you were kind enough to alert me to the existence of
2018 Mar 31
1
Names of variables needed in newdata for predict.glm
all.vars works fine, EXCEPT, it give a bit too much.
I only want the regression variables, but in the following example I also get "k" the variable holding the chosen knots. Any machinery to find only "real" regression variables?
cheers, Bendix
library( splines )
y <- rnorm(100)
x <- rnorm(100)
k <- -1:1
ml <- lm( y ~ bs(x,knots=k) )
mg <- glm( y ~
2002 May 13
1
prettyNum inserts leading commas (PR#1548)
Under R-1.5.0 on Solaris 2.6:
R> prettyNum(123456789, big.mark=",")
[1] ",123,456,789"
and that bad behavior (leading comma) spills into formatC as well:
R> formatC(123456789, digits=0, format="f", big.mark=",")
[1] ",123,456,789"
Looks to me like a bug in src/library/base/R/format.R, in function prettyNum:
B.[i.big] <-
2013 Mar 14
3
how to change "`Year_Month)201103`" into "Year_Month)201103" using R?
HI,
I have the pattern like "`Year_Month)201103`" I want to delete single quotes within double quetes.
I want to change it into "Year_Month)201103" , how to do it in r?
Thanks a lot.
Tammy
[[alternative HTML version deleted]]
2004 Aug 27
3
gsub, backslash and xtable
R Version 1.9.1 (2004-06-21)
Mac OS X.3.5 Dual 2GHz PowerPC G5
GUI = "AQUA"
I have a data.frame comprising percentiles with the column headings
containing % characters, e.g.
> (pp <- colnames(temp2))
[1] "5%" "10%" "25%" "50%" "75%" "90%" "95%"
I use xtable to convert the data.frame to Latex but I want to
2008 Jan 04
1
patch for html display
All,
I''ve found that the html view for the rspec formatter falls to pieces with
Rails 2.02 and rspec 1.10. Has anyone else run into this trouble?
Here''s a monkey patch that fixes the problem. A more elegant fix would be
in order, but this gets the job done:
Index:
/Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb
2005 Nov 27
4
gsub syntax
Hello
I know that R's string functions are not as extensive as those of Unix but
I need to do some text handling totally within an R environment because
the target is a Windows system which will not have the corresponding shell
utilities, sed, awk etc.
Can anyone explain the following gsub phenomenon to me:
>
2012 Mar 18
3
assign a value to an element
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?...
Nom : non disponible
URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20120318/d68edf35/attachment.pl>
2018 Mar 08
0
Names of variables needed in newdata for predict.glm
Hi,
Some try:
> names(mi$xlevels)
[1] "f"
> all.vars(mi$formula)
[1] "D" "x" "f" "Y"
> names(mx$xlevels)
[1] "f"
> all.vars(mx$formula)
[1] "D" "x" "f"
When offset is indicated out of the formula, it does not work...
Marc
Le 07/03/2018 ? 06:20, Bendix Carstensen a ?crit?:
> I would like
2018 Mar 07
3
Names of variables needed in newdata for predict.glm
I would like to extract the names, modes [numeric/factor] and levels
of variables needed in a data frame supplied as newdata= argument to
predict.glm()
Here is a small example illustrating my troubles; what I want from
(both of) the glm objects is the vector c("x","f","Y") and an
indication that f is a factor:
library( splines )
dd <- data.frame( D =
2008 Feb 12
6
Matching Problem
Hi
I have this vector of strings.
MyData <- c("Test1","Test2","I(Test1^2)","I(Test2^3)","I(Test1.Test2^2)")
where I want to extract only the text after "I(" and before "^" so that the
string returned only contain c("Test1","Test2","Test1.Test2")
I am not very skilled in the use of matching
2008 Apr 26
2
3 questions: debug R script, multi-level sorts, and multi-gsub
Hi,
1) I ran a script say test.R. It ran and terminated with an error. However,
I am not sure where the error occur.
> source("test.R")
Loading required package: tools
Welcome to Bioconductor
Vignettes contain introductory material. To view, type
'openVignette()'. To cite Bioconductor, see
'citation("Biobase")' and for packages
2010 Dec 15
3
How to apitalize leading letters & else of personal names?
Dear R world,
Do you know about a function that would capitalize in the correct manner
first and family names?
I found in the cwhmisc only the CapLeading function, but it just does not do
the job, taking care only to capitalize the first letter of a word.
I am looking for a function that would recognize " |'|Mc|-" and capitalize
the first letter following these characters.
An
2003 Feb 19
3
removing leading/trailing blanks
Hi,
What's the best way of dropping leading or trailing
blanks from a character string?
The only thing I can think of is using sub() to replace
blanks with null strings, but I don't know if there is
a better way (I also don't know how to represent the
trailing blank in a regular expression).
Thanks,
Doug Grove
2007 Jun 22
2
extract index during execution of sapply
Hi there
During execution of sapply I want to extract the number of times the
function given to supply has been executed. I came up with:
mylist <- list(a=3,b=6,c=9)
sapply(mylist,function(x)as.numeric(gsub("[^0-9]","",deparse(substitute(x)))))
This works fine, but looks quite ugly. I'm sure that there's a more
elegant way to do this.
Any suggestion?
Christian
2013 May 01
1
Windows, format.POSIXct and character encodings
Hi all,
In what encoding does format.POSIXct return its output? It doesn't
seem to be utf-8:
Sys.setlocale("LC_ALL", "Japanese_Japan.932")
times <- c("1970-01-01 01:00:00 UTC", "1970-02-02 22:00:00 UTC")
ampm <- format(as.POSIXct(times), format = "%p")
x <- gsub(">", "*", paste(ampm, collapse =
2008 Jun 04
0
Change simple format
Hi,
I am changed simple format method and added first line code for
replacing spaces
for formatting in this it works but other code means new line
paragraphs are not working?
I want a such method which format all white spaces, new line,
paragraphs.
how it possible in ruby?
example:
def my_format(text)
text.gsub!(/('' '')/, " ")