Printing list outputs into a file

42 views
Skip to first unread message

maryuale

unread,
Nov 3, 2009, 10:47:35 PM11/3/09
to StatForLing with R
Hi there,

I'm a newbie in R, so I hope to get some tips...

I wrote a script that basically takes some csv files and calculates
the Kappa statistics for the data in each file (I used the
kappam.fleiss() function from the “irr” library).

The script works fine (after some trouble with the loop, I finally
nailed it :D). The problem is that the output format of the
kapam.fleiss function is a list, and I want to print that output into
a file. As far as I tried, neither cat() or write.table() or any
function can handle it appropriately.

Here is an example of the output:

> result<-kappam.fleiss(teste, detail=TRUE); result
Fleiss' Kappa for m Raters



Subjects = 822

Raters = 3

Kappa = 0.875



z = 43.5

p-value = 0



Kappa z p.value

# 0.875 43.460 0.000

0 0.875 43.460 0.000

I've tried to unlist, but the output comes out kinda messy:

> unlist(result)
method subjects

"Fleiss' Kappa for m Raters" "822"

raters irr.name

"3" "Kappa"

value detail1

"0.87518077167814" "0.875"

detail2 detail3

"0.875" "43.46"

detail4 detail5

"43.46" "0"

detail6 stat.name

"0" "z"

statistic p.value

"43.4604584739041" "0"


So, does anybody knows how to send the exact output, as showed in
screen, to a txt file?

Stefan Th. Gries

unread,
Nov 3, 2009, 10:50:18 PM11/3/09
to statforli...@googlegroups.com
Have you tried accessing parts of the list as follows?

(x <- list(1:3, 4:6, letters[1:3], factor(letters[14:16])))
unlist(sapply(x, "[", 2)) # creates a vector that contains the second
part of each list element

Cheers,
STG
--
Stefan Th. Gries
-----------------------------------------------
University of California, Santa Barbara
http://www.linguistics.ucsb.edu/faculty/stgries
-----------------------------------------------

maryuale

unread,
Nov 3, 2009, 10:58:48 PM11/3/09
to StatForLing with R
That was fast!
I'll try it, thanks!
Reply all
Reply to author
Forward
0 new messages