[R] Printing column names before each block of output (fwd)
A Singh
Aditi.Singh at bristol.ac.uk
Tue Sep 22 12:23:35 CEST 2009
Hi Jim,
I checked vcdf for names() , (this is my test data set),
and it does have names:
>names(vcdf)
[1] "male.parent" "family" "offspring.id" "P1L55" "P1L73"
[6] "P1L74" "P1L77" "P1L91" "P1L96" "P1L98"
[11] "P1L100" "P1L114" "P1L118" "peg.no"
"ec.length"
[16] "syll.length"
I also ran my code after inserting cat() and your command, but its giving
me blank lines.
for ( c in phen)
{
print("Phenotype")
cat(names(c), "\n")
for ( f in colms)
{
print("Marker")
cat(names(f), "\n")
fit<-lmer(data=vcdf, c~1 + (1|family/f))
print(summary(fit))
}}
[1] "Phenotype"
[1] "Marker"
Linear mixed model fit by REML
-
-
-
Number of obs: 390, groups: f:family, 82; family, 57
Fixed effects:
Estimate Std. Error t value
(Intercept) 96.577 1.376 70.2
[1] "Marker"
Linear mixed model fit by REML
-
-
.
.
.
Am I doing this correctly?
I've tried variations and it all behaves the same. Hope I'm not missing
something obvious...
--On 22 September 2009 10:06 +1000 Jim Lemon <jim at bitwrit.com.au> wrote:
> 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
>
----------------------
A Singh
Aditi.Singh at bristol.ac.uk
School of Biological Sciences
University of Bristol
More information about the R-help
mailing list