I have created many functionss that I would like to apply on a sublists of a list (i.e. nestedlist) .
For example
# Getintervalduration
list.dur <- function(x){
# x is a (non nested...) list
dur <- x$xmax-x$xmin
return(dur)
}
So I can get to apply this function on :
(1) a simple dataframe in my list
list.dur(intrad_02.textgrid$phones)
(2) all the dataframes in my list
lapply(intrad_02.textgrid, list.dur)
(3) all the nested list in my main list and dataframes in the list
durations <- lapply(txtgridnames,list.dur)
The third example is what I want to succeed in doing automatically.
For now, txtgridnames
corresponds more or less to names(list)
But I had to modify it semiautomatically, because :
R does allow :
durations <- lapply(c(firstnestedlist, second.nested.list, etc.),list.dur)
But unfortunatly doesn't allow this:
durations <- lapply(names(list.with.nested.lists.inside),list.dur)
Which is a problem when the names(list)
could change or want to be replicated on a different study case.
For the moment so, my solution (thinkering here) is to write a table with the names without "quote" and with coma as eol, to read this file i just created with the names and then to create an object manually with all the names.
write.table(x=names(corpus),file="txtgridnames.txt", quote=FALSE, row.names=FALSE, append=FALSE, eol=",",col.names=FALSE)
txtgridnames <- readLines("txtgridnames.txt")
txtgridnames
!Copy Manuyally the output!..and paste it manually such that :
txtgridnames<-c(cnf_01_be,cnf_02_ch[...])
How to automatically get R to understand list(names(mainlist)), i.e. how to automatically create this object "txtgridnames" ?
Here is an example of the datastructure I am dealing with to be clear : (about 502 dataframes in 24 sublists in a main list that constitute my corpus)
A former post also describes the kind of data I am dealing with more precisely (to know what xmin and xmax correspond click here
#-------------------------------------------
## Data structure example
$ cnf_01_be :List of 17
..$ phones :'data.frame': 2505 obs. of 3 variables:
.. ..$ xmin : num [1:2505] 0 0.427 0.472 0.512 0.562 ...
.. ..$ xmax : num [1:2505] 0.427 0.472 0.512 0.562 0.632 ...
.. ..$ value: chr [1:2505] "_" "v" "w" "a" ...
..$ syll :'data.frame': 1146 obs. of 3 variables:
.. ..$ xmin : num [1:1146] 0 0.427 0.562 0.752 0.952 ...
.. ..$ xmax : num [1:1146] 0.427 0.562 0.752 0.952 1.022 ...
.. ..$ value: chr [1:1146] "_" "vwa" "la" "do~k" ...
..$ delivery :'data.frame': 1146 obs. of 3 variables:
.. ..$ xmin : num [1:1146] 0 0.427 0.562 0.752 0.952 ...
.. ..$ xmax : num [1:1146] 0.427 0.562 0.752 0.952 1.022 ...
.. ..$ value: chr [1:1146] "_" "" "" "" ...
..$ link :'data.frame': 806 obs. of 3 variables:
.. ..$ xmin : num [1:806] 0 0.427 0.752 0.952 1.082 ...
.. ..$ xmax : num [1:806] 0.427 0.752 0.952 1.082 1.256 ...
.. ..$ value: chr [1:806] "_" "" "" "l" ...
..$ words :'data.frame': 806 obs. of 3 variables:
.. ..$ xmin : num [1:806] 0 0.427 0.752 0.952 1.082 ...
.. ..$ xmax : num [1:806] 0.427 0.752 0.952 1.082 1.256 ...
.. ..$ value: chr [1:806] "_" "voilà" "donc" "vous" ...
..$ POS :'data.frame': 806 obs. of 3 variables:
.. ..$ xmin : num [1:806] 0 0.427 0.752 0.952 1.082 ...
.. ..$ xmax : num [1:806] 0.427 0.752 0.952 1.082 1.256 ...
.. ..$ value: chr [1:806] "_" "VER:pres:entatif" "CON:coo" "PRO:sjt" ...
..$ discourse :'data.frame': 750 obs. of 3 variables:
.. ..$ xmin : num [1:750] 0 0.427 0.752 0.952 1.082 ...
.. ..$ xmax : num [1:750] 0.427 0.752 0.952 1.082 1.256 ...
.. ..$ value: chr [1:750] "SIL:l" "MD" "CON" "" ...
..$ disfluency :'data.frame': 806 obs. of 3 variables:
.. ..$ xmin : num [1:806] 0 0.427 0.752 0.952 1.082 ...
.. ..$ xmax : num [1:806] 0.427 0.752 0.952 1.082 1.256 ...
.. ..$ value: chr [1:806] "SIL:l" "" "" "" ...
..$ boundary-dismo:'data.frame': 750 obs. of 3 variables:
.. ..$ xmin : num [1:750] 0 0.427 0.752 0.952 1.082 ...
.. ..$ xmax : num [1:750] 0.427 0.752 0.952 1.082 1.256 ...
.. ..$ value: chr [1:750] "MAJ" "MAJ" "MINg" "" ...
..$ speaker :'data.frame': 1 obs. of 3 variables:
.. ..$ xmin : num 0
.. ..$ xmax : num 244
.. ..$ value: chr "1"
..$ ortho :'data.frame': 101 obs. of 3 variables:
.. ..$ xmin : num [1:101] 0 0.427 3.571 4.3 7.659 ...
.. ..$ xmax : num [1:101] 0.427 3.571 4.3 7.659 8.341 ...
.. ..$ value: chr [1:101] "_" "voilà donc vous avez bien perçu même intuitivement qu'y avait euh" "_" "des choses issues de radios commerciales ou de radios classiques etcaetera" ...
..$ rection :'data.frame': 117 obs. of 3 variables:
.. ..$ xmin : num [1:117] 0 0.427 0.752 0.952 7.659 ...
.. ..$ xmax : num [1:117] 0.427 0.752 0.952 7.659 8.341 ...
.. ..$ value: chr [1:117] "" "md" "md" "urv" ...
..$ sequences :'data.frame': 183 obs. of 3 variables:
.. ..$ xmin : num [1:183] 0 0.427 0.752 0.952 1.942 ...
.. ..$ xmax : num [1:183] 0.427 0.752 0.952 1.942 2.848 ...
.. ..$ value: chr [1:183] "" "md" "md" "SV" ...
..$ boundary :'data.frame': 0 obs. of 3 variables:
.. ..$ xmin : num(0)
.. ..$ xmax : num(0)
.. ..$ value: chr(0)
..$ contours :'data.frame': 1143 obs. of 3 variables:
.. ..$ xmin : num [1:1143] 0 0.427 0.562 0.752 0.952 ...
.. ..$ xmax : num [1:1143] 0.427 0.562 0.752 0.952 1.022 ...
.. ..$ value: chr [1:1143] "" "" "C" "" ...
..$ bdu-auto :'data.frame': 53 obs. of 3 variables:
.. ..$ xmin : num [1:53] 0 0.427 7.659 8.341 18.861 ...
.. ..$ xmax : num [1:53] 0.427 7.659 8.341 18.861 19.624 ...
.. ..$ value: chr [1:53] "" "bdu-1-c_C" "" "bdu-2-s_C" ...
..$ EPG :'data.frame': 54 obs. of 3 variables:
.. ..$ xmin : num [1:54] 0 0.427 0.952 8.341 8.806 ...
.. ..$ xmax : num [1:54] 0.427 0.952 8.341 8.806 19.624 ...
.. ..$ value: chr [1:54] "" "PGC-R" "" "PGC-R" ...
$ cnf_02_ch :List of 17
..$ phones :'data.frame': 2304 obs. of 3 variables:
.. ..$ xmin : num [1:2304] 0 0.001 0.219 0.866 0.886 ...
.. ..$ xmax : num [1:2304] 0.001 0.219 0.866 0.886 0.944 ...
.. ..$ value: chr [1:2304] "_" "n" "y" "m" ...
..$ syll :'data.frame': 1080 obs. of 3 variables:
.. ..$ xmin : num [1:1080] 0 0.001 0.866 1 1.089 ...
.. ..$ xmax : num [1:1080] 0.001 0.866 1 1.089 1.239 ...
.. ..$ value: chr [1:1080] "_" "na~" "m9~t" "" ...
..$ delivery :'data.frame': 1080 obs. of 3 variables:
.. ..$ xmin : num [1:1080] 0 0.001 0.866 1 1.089 ...
.. ..$ xmax : num [1:1080] 0.001 0.866 1 1.089 1.239 ...
.. ..$ value: chr [1:1080] "_" "" "" "" ...
..$ words :'data.frame': 784 obs. of 3 variables:
.. ..$ xmin : num [1:784] 0 0.219 0.866 1.089 1.239 ...
.. ..$ xmax : num [1:784] 0.219 0.866 1.089 1.239 1.691 ...
.. ..$ value: chr [1:784] "_" "humains" "maintenant" "la" ...
..$ link :'data.frame': 784 obs. of 3 variables:
.. ..$ xmin : num [1:784] 0 0.219 0.866 1.089 1.239 ...
.. ..$ xmax : num [1:784] 0.219 0.866 1.089 1.239 1.691 ...
.. ..$ value: chr [1:784] "_" "" "" "" ...
..$ POS :'data.frame': 784 obs. of 3 variables:
.. ..$ xmin : num [1:784] 0 0.219 0.866 1.089 1.239 ...
.. ..$ xmax : num [1:784] 0.219 0.866 1.089 1.239 1.691 ...
.. ..$ value: chr [1:784] "_" "ADJ:adj" "ADV:adv" "DET:def" ...
..$ disfluency :'data.frame': 785 obs. of 3 variables:
.. ..$ xmin : num [1:785] 0 0.219 0.866 1.089 1.239 ...
.. ..$ xmax : num [1:785] 0.219 0.866 1.089 1.239 1.691 ...
.. ..$ value: chr [1:785] "SIL:l" "" "" "CORR-B" ...
..$ discourse :'data.frame': 728 obs. of 3 variables:
.. ..$ xmin : num [1:728] 0 0.219 0.866 1.089 1.239 ...
.. ..$ xmax : num [1:728] 0.219 0.866 1.089 1.239 1.691 ...
.. ..$ value: chr [1:728] "SIL:l" "" "" "" ...
..$ boundary-dismo:'data.frame': 728 obs. of 3 variables:
[...]
Thanks in advance !