Quantcast

How to output "0" after paste() ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to output "0" after paste() ?

vod vos
Hi everyone,



How to get "0" after init?



aa<- seq(2,7,0.5)



aa



[1] 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0



bb<- paste("why no dot zero",aa,"after init",sep="")



bb



the output are:



[1] "why no dot zero2after init"   "why no dot zero2.5after init"

[3] "why no dot zero3after init"   "why no dot zero3.5after init"

[5] "why no dot zero4after init"   "why no dot zero4.5after init"

[7] "why no dot zero5after init"   "why no dot zero5.5after init"

 [9] "why no dot zero6after init"   "why no dot zero6.5after init"

[11] "why no dot zero7after init"



What I want are like: "why no dot zero2.0after init"  ,"why no dot zero3.0after init"



I used round(), signif(), but it does not help. Any ideas?


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to output "0" after paste() ?

David Carlson
First, use plain text emails. Look that what conversion from html did to your email:

aa <- seq(2,7,0.5) became aa&lt;- seq(2,7,0.5)

You need to format your numeric values with sprintf():

paste("why no dot zero", sprintf("%3.1f", aa),"after init",sep="")

?sprintf for details

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of vod vos
Sent: Monday, February 13, 2017 10:28 AM
To: r-help <[hidden email]>
Subject: [R] How to output "0" after paste() ?

Hi everyone,



How to get "0" after init?



aa&lt;- seq(2,7,0.5)



aa



[1] 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0



bb&lt;- paste("why no dot zero",aa,"after init",sep="")



bb



the output are:



[1] "why no dot zero2after init"   "why no dot zero2.5after init"

[3] "why no dot zero3after init"   "why no dot zero3.5after init"

[5] "why no dot zero4after init"   "why no dot zero4.5after init"

[7] "why no dot zero5after init"   "why no dot zero5.5after init"

 [9] "why no dot zero6after init"   "why no dot zero6.5after init"

[11] "why no dot zero7after init"



What I want are like: "why no dot zero2.0after init"  ,"why no dot zero3.0after init"



I used round(), signif(), but it does not help. Any ideas?


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to output "0" after paste() ?

Rui Barradas
In reply to this post by vod vos
Hello,

See the help page for ?sprintf.

sprintf("why no dot zero %1.1f after init", aa)

Hope this helps,

Rui Barradas

Em 13-02-2017 16:27, vod vos escreveu:

> Hi everyone,
>
>
>
> How to get "0" after init?
>
>
>
> aa&lt;- seq(2,7,0.5)
>
>
>
> aa
>
>
>
> [1] 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0
>
>
>
> bb&lt;- paste("why no dot zero",aa,"after init",sep="")
>
>
>
> bb
>
>
>
> the output are:
>
>
>
> [1] "why no dot zero2after init"   "why no dot zero2.5after init"
>
> [3] "why no dot zero3after init"   "why no dot zero3.5after init"
>
> [5] "why no dot zero4after init"   "why no dot zero4.5after init"
>
> [7] "why no dot zero5after init"   "why no dot zero5.5after init"
>
>   [9] "why no dot zero6after init"   "why no dot zero6.5after init"
>
> [11] "why no dot zero7after init"
>
>
>
> What I want are like: "why no dot zero2.0after init"  ,"why no dot zero3.0after init"
>
>
>
> I used round(), signif(), but it does not help. Any ideas?
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Loading...