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

______________________________________________
R-help@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.

Reply via email to