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 change the data in the table CSV file into a column and the row name is the original column name?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

How to use R language to change the data in the table CSV file into a column and the row name is the original column name? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

I received an email today asking questions like this:

Such an email is a direct email, with no pleasantries going straight to the subject. The only regret is that I don't know who wrote it.

If I understand correctly, the needs of the writer should look like this:

His raw data:

The data you want to get after processing:

Processing code:

Set.seed (123)

Dd = data.frame (ID = 1Jap10) dd (y2=rnorm (10), y3=rnorm (10), y4=rnorm (10))

Library (data.table) melt (dd,id=1)

Code interpretation:

1Perminence dd is the data frame data generated by simulation, the first is listed as ID, and the other is listed as characters

2. The function used is the melt function in the data.table package

In 3Jing melt, dd is the object data box, id is the constant number of columns, here is the ID column, the number of columns is 1, the other columns become a column, and then the column name becomes the row name.

The needs of the sender:

How to use R language to change the data in the table CSV file into a column, and the row name is the original column name? thank you.

1the dd CSV file, which can be read and named dd with the fread function

2. The data becomes a column. If there is no ID column, all of them are traits. You can run them like this: melt (dd), and the results are as follows:

Therefore, it is the application of a function melt.

The answer to the question about how to use R language to turn the data in the form CSV file into a column and the row name is the original list name is shared here. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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

Internet Technology

Wechat

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

12
Report