Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use R language to extract and compress .tar.gz.zip and other format files

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use R language to extract and compress .tar.gz.zip and other format files". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use R language to extract and compress .tar.gz.zip and other format files" bar!

.zip

Compression: zip ()

Decompress: unzip ()

To compress the file, enter the compressed file name directly in the first parameter of the zip () function, and enter the file name before compression in the second parameter.

It is even easier to extract the file, just use unzip () to add the name of the file that needs to be extracted.

.tar.gz

Compression: tar ()

Decompress: untar ()

A compressed file with the same .zip suffix.

.gz and .bz2

These two compressed files are the most different from the previous ones, because the files with these two suffixes can be called compressed files, or they can be read directly as a data file as data frame. Because it is a data file.

Let's explain in detail by decompressing / reading:

1) decompress directly

There is no function to extract the related files by default in R, so you need to use a package: R.utils, and then, as shown in the following code, you can extract it using the gunzip () function.

Library (R.utils) gunzip ("file.gz", remove = `TRUE`) bunzip2 ("file.bz2", remove = `TRUE`)

Note that there is an extra remove = parameter in this function. If you select TRUE, only the extracted files will be retained, and the original package will be deleted. The default is TRUE.

After decompression, we can read it directly with read.table ().

2) read directly

Of course, if our goal is to read the data, and not necessarily to extract it, we can read the data directly in the form of a combination of two default functions:

Dat

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report