Dear all, I would like to save few variable-names with their values in a tabular form, with that I mean that files can be printed easily in R in a tabular form and also saved in a ascii file that when one opens it see also the variables in a nice tabular format. IS that possible? Below a small example of how should look results in R and in a txt file. Postal Code | Superb City1 | 2134 | 2 City2 | 254 | 5 City3 | 12 | 54433 I am ok if you can give me some hard coded example to try. Regards Alex [[alternative HTML version deleted]]
Eik Vettorazzi
2012-Jul-26 11:46 UTC
[R] Variables in a Tabular form. easily saved in a txt file
Hi Alex,
sprintf with left alignment might be a start:
cat(sprintf("%-7s| %-12d|
%-5d",paste("City",1:3,sep=""),(12345)%/%10^c(1:3),c(2,5,54433)),sep="\n")
#cat has also a file option, see ?cat.
but acutally your given output doesn't look like a conventional table
but much more like this:
cat(sprintf(paste("%-7s| %-",12:14,"d|
%-5d",sep=""),paste("City",1:3,sep=""),(12345)%/%10^c(1:3),c(2,5,54433)),sep="\n")
cheers.
Am 26.07.2012 13:29, schrieb Alaios:> Dear all,
> I would like to save few variable-names with their values in a tabular
form, with that I mean
>
> that files can be printed easily in R in a tabular form and also saved in a
ascii file that when one opens it see also the variables in a nice tabular
format.
>
> IS that possible? Below a small example of how should look results in R and
in a txt file.
>
>
>
>
>
>
> Postal Code | Superb
> City1 | 2134 | 2
> City2 | 254 | 5
> City3 | 12 | 54433
>
>
>
> I am ok if you can give me some hard coded example to try.
>
>
>
> Regards
> Alex
> [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at 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.
>
--
Eik Vettorazzi
Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und
Genossenschaftsregister sowie das Unternehmensregister (EHUG):
Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen Rechts;
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr.
Alexander Kirstein, Joachim Pr?l?, Prof. Dr. Dr. Uwe Koch-Gromus
HI,
Not sure if this is what you are looking for.
Try:
dat1<-read.table(text="
???? Postal Code | Superb
City1?? |?? 2134????????? |? 2
City2?? |?? 254??????????? |? 5
City3?? |?? 12????????????? |? 54433
",sep="|",header=TRUE)
?Postal.Code1<-paste0("|",dat1$Postal.Code)
Supertb1<-paste0("|",dat1$Superb)
?dat2<-data.frame(Postal.Code=Postal.Code1,Superb=Supertb1)
?rownames(dat2)<-rownames(dat1)
write.table(dat2,"dat6.txt",quote=FALSE)
#saving it as table format in html
library(xtable)
print(xtable(dat1),type="html",file="clipboardnew")
#another way to save it on plot.
library(plotrix)
?plot(0:3,0:3,xlab="",ylab="",type="n",axes=FALSE)
?addtable2plot(1,1,dat1,cex=1)
A.K.
----- Original Message -----
From: Alaios <alaios at yahoo.com>
To: R help <R-help at r-project.org>
Cc:
Sent: Thursday, July 26, 2012 7:29 AM
Subject: [R] Variables in a Tabular form. easily saved in a txt file
Dear all,
I would like to save few variable-names with their values in a tabular form,
with that I mean
that files can be printed easily in R in a tabular form and also saved in a
ascii file that when one opens it see also the variables in a nice tabular
format.
IS that possible? Below a small example of how should look results in R and in a
txt file.
??? ???????? Postal Code | Superb
City1?? | ? 2134????????? |? 2
City2 ? | ? 254 ? ? ?????? |? 5
City3 ? | ? 12 ? ? ???? ? ? |? 54433
I am ok if you can give me some hard coded example to try.
Regards
Alex
??? [[alternative HTML version deleted]]
______________________________________________
R-help at 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.
HI, I guess this should be the one: dat1<-read.table(text=" ???? Postal Code | Superb City1?? |?? 2134????????? |? 2 City2?? |?? 254??????????? |? 5 City3?? |?? 12????????????? |? 54433 ",sep="|",header=TRUE) write.table(dat1,"dat7.txt",sep="|",quote=FALSE) #contents of dat7.txt Postal.Code|Superb City1?? |2134|2 City2?? |254|5 City3?? |12|54433 A.K. ----- Original Message ----- From: Alaios <alaios at yahoo.com> To: R help <R-help at r-project.org> Cc: Sent: Thursday, July 26, 2012 7:29 AM Subject: [R] Variables in a Tabular form. easily saved in a txt file Dear all, I would like to save few variable-names with their values in a tabular form, with that I mean that files can be printed easily in R in a tabular form and also saved in a ascii file that when one opens it see also the variables in a nice tabular format. IS that possible? Below a small example of how should look results in R and in a txt file. ??? ???????? Postal Code | Superb City1?? | ? 2134????????? |? 2 City2 ? | ? 254 ? ? ?????? |? 5 City3 ? | ? 12 ? ? ???? ? ? |? 54433 I am ok if you can give me some hard coded example to try. Regards Alex ??? [[alternative HTML version deleted]] ______________________________________________ R-help at 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.
John Kane
2012-Jul-26 15:49 UTC
[R] Variables in a Tabular form. easily saved in a txt file
It is really not clear what you want without some idea of what the variables and
data look like.
However if the data is in a couple of vectors you could try something like this
postal <- c(2134, 54, 12)
superb <- c(2,5,54433)
cities <- c("City1", "City2", "City3")
hds <- c("Postal.Code", "Superb")
mat <- matrix( c(postal, superb), nrow=3)
colnames(mat) <- hds
rownames(mat) <- cities
mat
dat1 <- data.frame(cities, postal, superb)
names(dat1) <- c("city", "postal.code", superb)
dat1
Both of these can be save to a text file using
?write.table
John Kane
Kingston ON Canada
> -----Original Message-----
> From: alaios at yahoo.com
> Sent: Thu, 26 Jul 2012 04:29:07 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] Variables in a Tabular form. easily saved in a txt file
>
> Dear all,
> I would like to save few variable-names with their values in a tabular
> form, with that I mean
>
> that files can be printed easily in R in a tabular form and also saved in
> a ascii file that when one opens it see also the variables in a nice
> tabular format.
>
> IS that possible? Below a small example of how should look results in R
> and in a txt file.
>
>
>
> Postal Code | Superb
> City1 | 2134 | 2
> City2 | 254 | 5
> City3 | 12 | 54433
>
>
>
> I am ok if you can give me some hard coded example to try.
>
>
>
> Regards
> Alex
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and
family!
Visit http://www.inbox.com/photosharing to find out more!