Output formatting in Latex and R

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Output formatting in Latex and R

Manish Gupta
I am working on Latex and R and using following code.

<<echo=FALSE>>=
infile<-read.table("test.txt",sep="\t")
Col3 <- unique(infile[,3])
LCol3 <- length(Col3)
for (i in 1:LCol3) {


print(paste("Column", Col3[i]))
print(infile[infile[,3]==Col3[i],-3])
}
@

I am getting following output.

1] "Column C" V1 V2 V4 1 A B D 2 X T K [1] "Column Z" V1 V2 V4 3 Z U M 4 E V R 5 Z U M [1] "Column P" V1 V2 V4 6 E V R

    Blockquote

I want to avoid numbering and columns names. I want my output as follows.

"Column C" A B D X T K

"Column Z" Z U M E V R Z U M

"Column P" E V R

How can i implement it?
Reply | Threaded
Open this post in threaded view
|

Re: Output formatting in Latex and R

priyank
Col3 <- unique(Msg17$V3)
LCol3 <- length(Col3)
for (i in 1:LCol3) {
  print(paste("Column", Col3[i]))
  write.table(Msg17[Msg17$V3==Col3[i],-3], row.names=F, col.names=F,quote=F)
# If you R implementation does not accept 'F', use 'FALSE'
}
Reply | Threaded
Open this post in threaded view
|

Re: Output formatting in Latex and R

Manish Gupta
Great it works! But how can i put space or tab between two records?
Reply | Threaded
Open this post in threaded view
|

Re: Output formatting in Latex and R

Manish Gupta
Hi,

I am using follosing code and getting the below output.
<<echo=FALSE>>=
infile<-read.table("/home/manish/Desktop/test.txt",sep="\t",header=TRUE)
Col3 <- unique(infile[,3])
LCol3 <- length(Col3)
for (i in 1:LCol3) {
print(paste("Disease Risk:", Col3[i]),row.names=FALSE, col.names=FALSE,quote=FALSE)
print(infile[infile[,3]==Col3[i],-3], row.names=FALSE, col.names=FALSE,quote=FALSE, width="10",  justify = c("right", "right", "centre"))
}
@


Still [1] is written over there. How to avoid it? And i need to add tab  and new line in between records. How can i implement it? Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Output formatting in Latex and R

priyank
Use the eol="\n\n" option. The records should have a 2 line space.
Reply | Threaded
Open this post in threaded view
|

Re: Output formatting in Latex and R

Manish Gupta
How to avoid [1] in output?

print(sqrt(2),row.names=NULL)
[1] 1.414214

How to avoid it?

 print(sqrt(2),row.names=NULL)
1.414214
Regards
Reply | Threaded
Open this post in threaded view
|

Re: Output formatting in Latex and R

Jorge I Velez
Hi Manish,

Try

> cat(sqrt(2),"\n")
1.414214

See ?cat for more information.

HTH,
Jorge.-


On Mon, Mar 19, 2012 at 10:42 PM, Manish Gupta <> wrote:

> How to avoid [1] in output?
>
> print(sqrt(2),row.names=NULL)
> *[1] *1.414214
>
> How to avoid it?
>
>  print(sqrt(2),row.names=NULL)
> 1.414214
> Regards
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Output-formatting-in-Latex-and-R-tp4483631p4487480.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.