[R] (no subject)^2
(Ted Harding)
Ted.Harding at manchester.ac.uk
Thu Jul 2 16:50:01 CEST 2009
Putting your two queries together [see revised Subject ... ]:
[R] (no subject)^1:
Could you please help me?
I am trying to load an csv-file in R, but it works wrong!
My data is
0,0127
-0,0016
0,0113
0,0037
-0,0025
>
> Ret
X0 X0127
1 0 16
2 0 113
3 0 37
4 0 25
In this case, you need to use the "header=FALSE" option to read.csv():
Ret<-read.csv("Ret.csv", header=FALSE)
since the default for read.csv() is "header=TRUE", so it assigns
names to the variables (col1 and col2) according to what is in the
first line. Since your first line had numeric data, it appends these
to "X". Read what you get from
?read.csv
[R] (no subject)^2
Hi Guys,
It is very simple question, but I can't find the answer! Please
help me.
I use R and such simple function as length() doesn't work. The
result is always 1 even if my data are more then 1 observations!
Do I have to load any additional library?
> length(Ret_1)
[1] 1
> length
function (x) .Primitive("length")
Thank you!!!
I surmise that "Ret_1" is the result of a command similar to your
Ret<-read.csv("Ret.csv")
Hence it is a dataframe.
If I use your Ret<-read.csv("Ret.csv") command with your "Ret.csv"
data, I get, as you did:
Ret
# X0 X0127
# 1 0 16
# 2 0 113
# 3 0 37
# 4 0 25
Here, Ret is a dataframe with two "columns". In fact, a dataframe
is a special kind of list, one element for each column:
str(Ret)
# 'data.frame': 4 obs. of 2 variables:
# $ X0 : int 0 0 0 0
# $ X0127: int 16 113 37 25
and each "$" is one element of the list: $X0 and $X0127. Each element
is a vector of numbers in the case of your "Ret".
You can see what they are separately by using the "$" operator
to extract them:
Ret$X0
# [1] 0 0 0 0
Ret$X0127
# [1] 16 113 37 25
So "Ret" is a list with 2 elements. Hence:
length(Ret)
# [1] 2
Therefore, in the case of your "Ret_1", I surmise that your "Ret_1"
is a list with one element (as Sarah Goslee surmised also).
In other words, if you constructed "Ret_1" by reading from a CSV
file, as in
Ret<-read.csv("Ret.csv")
you will have a dataframe with 1 "column", namely a list with one
element.
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 02-Jul-09 Time: 15:49:56
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list