[英]How to delete some column based on the column headings of a csv file in R?
I have loaded a csv file to R. 我已将csv文件加载到R。
There are 10 columns in the file. 文件中有10列。
I want to save the 1st 3rd and 5th column to a new file. 我想将第一,三,五列保存到一个新文件中。 What is the command line to delete other columns?
删除其他列的命令行是什么?
I want to save the new table, what is the command line should be used? 我要保存新表,应使用什么命令行?
First, I'll answer your question. 首先,我会回答你的问题。 If
d
is your data frame loaded from your file, then: 如果
d
是从文件加载的数据帧,则:
d_subset = d[,c(1,3,5)]
write.csv(d_subset, file="file.csv")
Second, I'll give you some advice. 第二,我给你一些建议。 Read the documentation or buy a good R book.
阅读文档或购买一本不错的R书。 You can even download An introduction to R for free.
您甚至可以免费下载R简介 。 Many of the questions you are asking are very basic.
您要问的许多问题都是非常基本的。 While most people are happy to handle the odd basic question, asking three or four a day really isn't sustainable.
虽然大多数人都乐于解决这个奇怪的基本问题,但每天问三四个人确实是不可持续的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.