如何将 .csv 文件导入 R? [英] How to get a .csv file into R?

查看:148
本文介绍了如何将 .csv 文件导入 R?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 .csv 文件:

I have this .csv file:

ID,GRADES,GPA,Teacher,State

3,"C",2,"Teacher3","MA"

1,"A",4,"Teacher1","California"

我想要做的是使用 R 统计软件读入文件并将标题读入某种列表或数组(我是 R 的新手,一直在寻找如何做到这一点,但是所以远没有运气).

And what I want to do is read in the file using the R statistical software and read in the Header into some kind of list or array (I'm new to R and have been looking for how to do this, but so far have had no luck).

这是我想要做的一些伪代码:

Here's some pseudocode of what I want to do:

inputfile=read.csv("C:/somedirectory")

for eachitem in row1:{

add eachitem to list
}

然后我希望能够使用这些名称来调用每个垂直列,以便我可以执行计算.

Then I want to be able to use those names to call on each vertical column so that I can perform calculations.

我已经在谷歌上搜索了一个小时,试图找出如何做到这一点,但没有多少专门处理标题.

I've been scouring over google for an hour, trying to find out how to this but there is not much out there on dealing with headers specifically.

感谢您的帮助!

推荐答案

您提到您将调用每个垂直列,以便您可以执行计算.我假设您只想检查每个变量.这可以通过以下方式完成.

You mention that you will call on each vertical column so that you can perform calculations. I assume that you just want to examine each single variable. This can be done through the following.

df <- read.csv("myRandomFile.csv", header=TRUE)

df$ID

df$GRADES

df$GPA

仅将数据分配给变量可能会有所帮助.

Might be helpful just to assign the data to a variable.

var3 <- df$GPA

这篇关于如何将 .csv 文件导入 R?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆