Managing data with R(R的数据管理)
When you have spent a lot of time getting a data frame into the desired form, youshouldn't need to recreate your work each time you restart your R session. To save adata structure to ale that can be reloaded later or transferred to another system, usethe save() function. The save() function writes one or more R data structures to thelocation speci ed by the file parameter. R datales have an .RData extension.(使用sava函数保存数据结构到本地。指定一个文件名参数,文件名以.RData为扩展名)Suppose you have three objects named x, y, and z that you would like to save in apermanentle. Regardless of whether they are vectors, factors, lists, or data frames,we could save them to ale named mydata.RData using the following command:(保存x, y,z三个对象到本地,如图1)
The load() command can recreate any data structures that have been saved toan .RData le. To load the mydata.RData le we saved in the preceding code,simply type:(load函数将重新创建保存在RData文件中的数据结构。见图2)
If you need to wrap up your R session in a hurry, the save.image() command willwrite your entire session to ale simply called .RData. By default, R will look forthisle the next time you start R, and your session will be recreated just as you hadleft it.(使用sava.image()函数保存当前会话到本地文件中,下次R启动时就会自动寻找这个文件。你保存在其中的会话就会重新创建)
After working on an R session for sometime, you may have accumulated a numberof data structures. The ls() listing function returns a vector of all the data structurescurrently in the memory. For example, if you've been following along with the codein this chapter, the ls() function returns the following:(使用ls函数列出内存中存在的所有对象)
R will automatically remove these from its memory upon quitting the session, but forlarge data structures, you may want to free up the memory sooner. The rm() removefunction can be used for this purpose. For example, to eliminate the m and subject1objects, simply type:(R还在会话结束时会自动清除内存中相关的对象。对于一些非常大的对象,就需要手动的及时释放,可以使用rm函数释放。)
Importing and saving data from CSV files(导入csv文件和保存数据到csv文件)
Given a patient datale named pt_data.csv located in the R working directory, theread.csv() function can be used as follows to load thele into R:(使用read.csv函数读取csv文件,见图3)
This will read the CSVle into a data frame titled pt_data. Just as we did previouslywhile c**tructing a data frame, we need to use the stringsAsFactors = FALSEparameter to prevent R from converting all text variables into factors. This step isbetter left to you, not R, to perform.(注意图3中 read.csv函数中参数stringsAsFactors = FALSE,这个是防止R自动将文本数据转换成因子数据结构)
By default, R assumes that the CSVle includes a header line listing the names ofthe features in the dataset. If a CSVle does not have a header, specify the optionheader = FALSE, as shown in the following command, and R will assign defaultfeature names in the V1 and V2 forms and so on:(默认情况下,R假定CSV文件是包含一个头行的,这行主要包含数据集的所有特性名称。如果CSV文件不包含的头行的话,需要在读取函数中指明如图4)
我想说这些你都懂吗
奔跑的狮子 发表于 2017-4-13 14:05
我想说这些你都懂吗
暂时这些事基础的 还能看懂 到后面的 就不一定了书是英文的 翻译是根据我自己的理解翻译的语言倒不是问题 难就难在很多数学知识上:cc81) 呵呵,祝你变大师! 咨询下这个是开发吗?看见函数,对象,结构,文件
页:
[1]