# NOT RUN {
## save type-frequency list for Brown corpus to external file
fname <- tempfile(fileext=".tfl.gz") # automatically compresses file
write.tfl(Brown.tfl, fname)
## file <fname> contains a compressed TAB-delimited table with fields
## k ... type ID (usually Zipf rank)
## f ... frequency of type
## type ... the type itself (here a word form)
## read it back in
New.tfl <- read.tfl(fname)
## same as Brown.tfl
summary(New.tfl)
summary(Brown.tfl)
print(New.tfl)
print(Brown.tfl)
head(New.tfl)
head(Brown.tfl)
stopifnot(isTRUE(all.equal(New.tfl, Brown.tfl))) # should by identical
# }
# NOT RUN {
## suppose you have a text file with a frequency list, one f per line, e.g.:
## f
## 14
## 12
## 31
## ...
## you can import this with read.tfl
MyData.tfl <- read.tfl("mylist.txt")
summary(MyData.tfl)
print(MyData.tfl) # ids in column k added by zipfR
## from this you can generate a spectrum with tfl2spc
MyData.spc <- tfl2spc(MyData.tfl)
summary(MyData.spc)
# }
Run the code above in your browser using DataLab