整理混乱的记事本数据 [英] Organizing Messy Notepad data

查看:186
本文介绍了整理混乱的记事本数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在记事本中有一些数据,很混乱.保存不同数据的任何不同列之间基本上都没有空间.我知道数据的空间. 例如,第1-2列是X,第7-10列是Y ....

I have some data in Notepad that is a mess. There is basically no space between any of the different columns which hold different data. I know the spaces for the data. For example, Columns 1-2 are X, Columns 7-10 are Y....

我该如何组织?可以在R中完成吗?最好的方法是什么?

How can I organize this? Can it be done in R? What is the best way to do this?

推荐答案

?read.fwf在这种情况下可能是一个不错的选择.

?read.fwf may be a good bet for this circumstance.

设置文件的路径:

temp <- "\pathto\file.txt"

然后设置文件中变量的宽度,如下所示.

Then set the widths of the variables within the file, as demonstrated below.

#1-2 = x, 3-10=y
widths <- c(2,8)

然后设置列的名称.

cols <- c("X","Y")

最后,将数据导入会话中的新变量中:

Finally, import the data into a new variable in your session:

dataset <- read.fwf(temp,widths,header=FALSE,col.names=cols)

这篇关于整理混乱的记事本数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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