Dear All,
I need to print the column names of variables before each block of output,
for a nested model with 2 levels (3 phenotypes * 10 markers).
This is so that my output is labeled, and I know which combination of
factors produces which set of REML estimates.
Currently my output looks like this:
[1] "Phenotype"
NULL ##this is where I want to insert colnames OR numbers 1-3
[1] "Marker"
NULL ##insert colnames again OR numbers 1-10
Linear mixed model fit by REML
- (data)
- (data)
Random effects:
-(data)
.
.
[1] "Marker"
NULL
Linear mixed model fit by REML
- (data)
- (data)
Random effects:
.
.
(3*10 combinations)
My code is as follows:
vc<-read.table("...",header=T)
vcdf<-data.frame(vc)
vcdf[2:13]<-lapply(vcdf[2:13,factor)
colms<-(vcdf)[4:13] ## these are the 10 markers. I put them in a new
variable to make running the loop simple.
phen<-(vcdf)[14:16] ##these are the 3 phenotypes
for( c in phen)
{
print("Phenotype")
print(colnames(c))
for( f in colms)
{
print("Marker")
print(colnames(f))
fit<-lmer(data=vcdf, c~1 + (1|family/f))
print(summary(fit))
}}
Any pointers on how to print either column names, or a sequence of numbers?
Thanks a lot for your help,
Aditi
----------------------
A Singh
Aditi.Singh at bristol.ac.uk
School of Biological Sciences
University of Bristol
Jim Lemon
2009-Sep-22 00:06 UTC
[R] Printing column names before each block of output (fwd)
On 09/21/2009 11:32 PM, A Singh wrote:> > Dear All, > > I need to print the column names of variables before each block of > output, > for a nested model with 2 levels (3 phenotypes * 10 markers). > This is so that my output is labeled, and I know which combination of > factors produces which set of REML estimates. > > Currently my output looks like this: > > [1] "Phenotype" > NULL ##this is where I want to insert colnames OR > numbers 1-3 > [1] "Marker" > NULL ##insert colnames again OR numbers 1-10 > Linear mixed model fit by REML > - (data) > - (data) > Random effects: > -(data) > . > . > [1] "Marker" > NULL > Linear mixed model fit by REML > - (data) > - (data) > Random effects: > . > . > (3*10 combinations) > > > My code is as follows: > > vc<-read.table("...",header=T) > vcdf<-data.frame(vc) > vcdf[2:13]<-lapply(vcdf[2:13,factor) > colms<-(vcdf)[4:13] ## these are the 10 markers. I put them in a new > variable to make running the loop simple. > > phen<-(vcdf)[14:16] ##these are the 3 phenotypes > > for( c in phen) > { > print("Phenotype") > print(colnames(c)) > for( f in colms) > { > print("Marker") > print(colnames(f)) > fit<-lmer(data=vcdf, c~1 + (1|family/f)) > print(summary(fit)) > }} > > Any pointers on how to print either column names, or a sequence of > numbers? >Hi Aditi, First check whether your data frame already has names: names(vcdf) if not, give it names: names(vcdf)<-paste("V",1:length(vcdf),sep="") substituting whatever you like for "V". Then: cat(names(c),"\n") ... cat(names(f),"\n") Jim