[R] conditional output of string to file n times...
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Wed Jul 7 10:01:58 CEST 2021
Since you say you have a file, in the code below I will read the data
from a connection. Then create the string.
txtfile <- "ABC 3
tc <- textConnection(txtfile)
df1 <- read.table(tc)
# "ABC" "ABC" "ABC" "DDG" "DDG" "DDG" "DDG" "DDG" "ABB" "ABB"
Hope this helps,
Às 14:27 de 06/07/21, Evan Cooch escreveu:
> Suppose I have a file with the the following structure - call the two
> space-separated fields 'label' and 'count':
> ABC 3
> DDG 5
> ABB 2
> What I need to do is parse each line of the file, and then depending on
> the value of count, write out the value of 'label' to a new file, but
> 'count' times. In other words, take the preceding, and output
> I was wondering if there was an elegant/simple way to do this? I can do
> this relatively easily in perl, or awk, but am stumped by getting a bit
> of R code to accomplish the same thing.
> Many thanks in advance...
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help