When I try to import a text file with over 6000 rows and 9 colums the output is showing me 8 columns in the same row and the 9th is below all others. Furthermore, only the last 500 rows show up in my console only containing the UnadjClose. How do I do it right?
I tried: Dataset<-read.table("AD.TXT",sep=",",header=TRUE)
File: Text f开发者_JS百科ile to be imported
This sounds like R is wrapping what it prints to the console based on width. By default, R wraps at 80 which you can override with options(width = XXX)
where XXX represents your desired width. ?options
has more information.
To ensure that your dataset was read in properly, I recommend using str()
which will return the characteristics of your data. Consider the following toy dataset:
Dataset <- data.frame(a = rnorm(6000), b = rnorm(6000), c = rnorm(6000)
, d = rnorm(6000), e = rnorm(6000), f = rnorm(6000), g = rnorm(6000)
, h =rnorm(6000), i = rnorm(6000))
> str(Dataset)
(Dataset)
'data.frame': 6000 obs. of 9 variables:
$ a: num -0.5784 -0.0951 0.4199 -0.0992 -1.6443 ...
$ b: num -2.41 -1.72 0.8 0.57 2.32 ...
$ c: num -1.195 -0.661 -1.071 0.449 0.94 ...
$ d: num 0.114 2.255 0.67 -1.301 -0.792 ...
$ e: num 0.841 -0.0103 -0.9778 -0.6208 1.0317 ...
$ f: num -0.716 -0.803 0.929 -1.967 -0.712 ...
$ g: num -1.066 2.407 0.698 1.465 -0.547 ...
$ h: num -0.6507 0.1766 -0.0675 0.2491 -0.4547 ...
$ i: num 0.297 -0.233 -0.479 -0.66 0.214 ...
If you want a more visual way to inspect the data, try edit(Dataset)
or View(Dataset)
.
Do you mean that when you print the data after reading it that not everything is printed and that the last column is printed below the others instead of to the right?
For the printing what matters is what R thinks the width of a line is, see ?options
and look at the section on 'width', sometimes this number gets updated automatically, sometimes it does not and you need to do it manually. The 'max.print' option may also be of interest. You can also look at the help for the print function you are using (possibly implicitly) to see if there are other options (number of digits, etc.) that you could set to make the print out easier to read.
If you just want to look at the data and have access to all of it then I would suggest using the 'View' function rather than printing it.
This is right. The display on the console is not how it is stored internally. If you really want to change the appearance in the console, you'll have to set the options, eg :
op <- options("width"=200)
# to determine how many columns are printed on the screen
Dataset
options(op)
Better use edit()
or View()
as the others suggested, or just open your file in EXCEL. Sorry for the swearing...
# auto width adjustment
.adjustWidth <- function(...){
options(width=Sys.getenv("COLUMNS"))
TRUE
}
.adjustWidthCallBack <- addTaskCallback(.adjustWidth)
That's it, finally I have it.
精彩评论