r语⾔读⼊csv⽂件_将CSV⽂件读⼊R中的数据帧
r语⾔读⼊csv⽂件
With the help of specific functions offered by R, reading the CSV files into data frames is much easier.
借助R提供的特定功能,将CSV⽂件读⼊数据帧要容易得多。
什么是CSV⽂件? (What is a CSV file?)
CSV is expanded as Comma, Separated, Values. In this file, the values stored are parated by a comma. This process of storing the data is much easier.
CSV扩展为逗号,分隔符,值。 在此⽂件中,存储的值⽤逗号分隔。 这种存储数据的过程要容易得多。
为什么CSV是最常⽤的数据存储⽂件格式? (Why CSV is the most ud file format for data storing?)
Storing the data in an excel sheet is the most common practice in many companies. In the majority of firms, people are storing data as comma-parated-values (CSV), as the process is easier than creating normal spreadsheets. Later they can u R’s built in packages to read and analyze the data.
违停告知单怎么处理
在Excel⼯作表中存储数据是许多公司中最常见的做法。 在⼤多数公司中,⼈们将数据存储为逗号分隔值(CSV),因为此过程⽐创建普通电⼦表格容易。 之后,他们可以使⽤R的内置程序包读取和分析数据。
Being the most popular and powerful statistical analysis programming language, R offers specific functions to read data into organized from a CSV file.
作为最流⾏和功能最强⼤的统计分析编程语⾔,R提供了特定的功能,可以将从CSV⽂件读取到组织好的 。
将CSV⽂件读取到数据框 (Reading CSV File to Data Frame)
In this short example, we will e how we can read a CSV file into organized data frames.
在这个简短的⽰例中,我们将看到如何将CSV⽂件读取为有组织的数据帧。
The first thing in this process is to getting and tting up the working directory. You need to choo the working path of the CSV file.
此过程中的第⼀件事是获取并设置⼯作⽬录。 您需要选择CSV⽂件的⼯作路径。
1.设置⼯作⽬录 (1. Setting up the working directory )
Here you can check the default working directory using getwd() function and you can also change the directory using the function twd().
我与读书在这⾥,您可以使⽤getwd()函数检查默认的⼯作⽬录,也可以使⽤twd()函数更改⽬录。
有干劲的微信群名>getwd() #Shows the default working directory
----> "C:/Urs/Dell/Documents"
> twd("C:\Urs\Dell\Documents\R-test data") #to t the new working Directory
> getwd() #you can e the updated working directory
---> "C:/Urs/Dell/Documents/R-test data"
2.导⼊和读取数据集/ CSV⽂件 (2. Importing and Reading the datat / CSV file)
弹力的作用点After the tting of the working path, you need to import the data t or a CSV file as shown below.
设置⼯作路径后,需要导⼊数据集或CSV⽂件,如下所⽰。
> readfile <- read.csv("")
Execute the above line of code in R studio to get the data frame as shown below.
在R studio中执⾏上述代码⾏以获取数据框架,如下所⽰。
狗的寿命是多少年
To check the class of the variable ‘readfile’, execute the below code.
要检查变量“ readfile”的类,请执⾏以下代码。
> class(readfile)
---> "data.frame"
In the above image you can e the data frame which includes the information of student names, their ID’s, departments, gender and marks.
在上图中,您可以看到数据框,其中包括学⽣姓名,学⽣的ID,部门,性别和标记的信息。
3.从CSV⽂件中提取学⽣的信息 (3. Extracting the student’s information from the CSV file)
After getting the data frame, you can now analy the data. You can extract particular information from the data frame.
获取数据框后,您现在可以分析数据。 您可以从数据框中提取特定信息。
To extract the highest marks scored by students,
要提取学⽣得分最⾼的分数,
>marks <- max(data$Marks.Scored) #this will give you the highest marks
#To extract the details of a student who scored the highest marks,
> data <- read.csv("traindata.csv")
> Marks <- max(data$Marks.Scored)
> retval <- subt(data, Marks.Scored == max(Marks.Scored)) #This will
extract the details of the student who cured highest marks
> View(retval)
To extract the details of the students who are in studying in ‘chemistry’ Dept,
要提取正在“化学”系学习的学⽣的详细信息,
> readfile <- read.csv("traindata.csv")
> retval <- subt( data, Department == "chemistry") # This will extract the student details who are in Biochemistry department > View(retval)
结论 (Conclusion )粘贴画
jlk
By this process you can read the csv files in R with the u of read.csv(“ “) function. This tutorial covers how to import the csv file and reading the csv file and extracting some specific information from the data frame.
通过此过程,您可以使⽤read.csv(“”)函数读取R中的csv⽂件。 本教程介绍如何导⼊csv⽂件,读取csv⽂件以及从数据框中提取⼀些特定信息。
I ud R studio for this project. RStudio offers great features like console, editor, and environment as well. Anyhow you are free to u other editors like Thinn-R, Crimson editor, etc. I hope this tutorial will help you in understanding the reading of CSV files in R and extracting some information from the data frame.
我为此项⽬使⽤了R studio。 RStudio还提供了出⾊的功能,例如控制台,编辑器和环境。 ⽆论如何,您都可以⾃由使⽤其他编辑器,例如Thinn-R,Crimson编辑器等。我希望本教程将帮助您理解R中CSV⽂件的读取并从数据框中提取⼀些信息。
有关更多信息,请访问: :打印机多少钱
r语⾔读⼊csv⽂件