[R] conditional output of string to file n times...
Evan Cooch
ev@n@cooch @end|ng |rom gm@||@com
Tue Jul 6 16:31:41 CEST 2021
Figured it out on my own. Basically, use the replicate command for each
line of the data.frame, then appending to a file.
On 7/6/2021 9:27 AM, Evan Cooch wrote:
> 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
>
> ABC
> ABC
> ABC
> DDG
> DDG
> DDG
> DDG
> DDG
> ABB
> ABB
>
> 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...
>
More information about the R-help
mailing list