Re: [R] reading csv-data

2005-06-19 Thread Johanna Sundvik
Thank you all for your help. 

There was an easy solution to my problem:

read.csv2(example.csv, dec=., header=TRUE)
or 
Mean1 - as.numeric(as.character(Mean1))

-Johanna


Lainaus Ivar Herfindal [EMAIL PROTECTED]:

 
 
 Thomas Lumley wrote:
 
  On Fri, 17 Jun 2005, Johanna Sundvik wrote:
  
 However, this Mean1 is categorical when it should be real numbers.
 
 
 Mean1
 
 [1] 4.4332  8.5113  35.1624 9.1693  2.974   65.1578 43.2241 3.1278  5.3364
 Levels: 2.974 3.1278 35.1624 4.4332 43.2241 5.3364 65.1578 8.5113 9.1693
 
 Why R does not understand that this should be real numbers? What am I
 doing
 wrong here? Thanks for your help.
 
  
  
  Your files must have some entries that are not numbers, such as . or 
  something.  R then can't tell that the field is supposed to be numeric. 
  This may happen with missing data, in which case the na.strings= argument 
  can be used to tell R how missing data are specified.
  
  You can convert the data to numeric as described in FAQ 7.10
  
  -thomas
  
 I think the problem can be that you use read.csv2(), which expect a 
 comma (,) as decimal-indicator (as is common in Scandinavia), and a 
 semi-colon (;) as separator between columns. Either you should try 
 read.csv(), or you can try read.csv2(example.csv, dec=., header=TRUE)
 
 Have a look at ?read.csv (read.csv2 is in the same help-text).
 
 Ivar
 
 __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] reading csv-data

2005-06-17 Thread Johanna Sundvik

Hi!

I have had this problem for a long time. I have tried to study the manuals and
search the mailing lists, but I can not solve this. I think there has to be one
simple solution to this, but I just can not find it. 

I have saved the data in excel (csv-format). Then I read the data in R e.g.

data - read.csv2(example.csv, header=TRUE)

I look the data and it looks ok. E.g

data
 Mean1   
1   4.4332  
2   8.5113  
3  35.1624 
4   9.1693 
52.974 
6  65.1578 
7  43.2241 
8   3.1278 
9   5.3364 
10  3.9767 

However, this Mean1 is categorical when it should be real numbers.

 Mean1
[1] 4.4332  8.5113  35.1624 9.1693  2.974   65.1578 43.2241 3.1278  5.3364 
Levels: 2.974 3.1278 35.1624 4.4332 43.2241 5.3364 65.1578 8.5113 9.1693

Why R does not understand that this should be real numbers? What am I doing
wrong here? Thanks for your help.

Regards,
Johanna Sundvik

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] reading csv-data

2005-06-17 Thread Thomas Lumley
On Fri, 17 Jun 2005, Johanna Sundvik wrote:
 However, this Mean1 is categorical when it should be real numbers.

 Mean1
 [1] 4.4332  8.5113  35.1624 9.1693  2.974   65.1578 43.2241 3.1278  5.3364
 Levels: 2.974 3.1278 35.1624 4.4332 43.2241 5.3364 65.1578 8.5113 9.1693

 Why R does not understand that this should be real numbers? What am I doing
 wrong here? Thanks for your help.


Your files must have some entries that are not numbers, such as . or 
something.  R then can't tell that the field is supposed to be numeric. 
This may happen with missing data, in which case the na.strings= argument 
can be used to tell R how missing data are specified.

You can convert the data to numeric as described in FAQ 7.10

-thomas

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] reading csv-data

2005-06-17 Thread Ivar Herfindal


Thomas Lumley wrote:

 On Fri, 17 Jun 2005, Johanna Sundvik wrote:
 
However, this Mean1 is categorical when it should be real numbers.


Mean1

[1] 4.4332  8.5113  35.1624 9.1693  2.974   65.1578 43.2241 3.1278  5.3364
Levels: 2.974 3.1278 35.1624 4.4332 43.2241 5.3364 65.1578 8.5113 9.1693

Why R does not understand that this should be real numbers? What am I doing
wrong here? Thanks for your help.

 
 
 Your files must have some entries that are not numbers, such as . or 
 something.  R then can't tell that the field is supposed to be numeric. 
 This may happen with missing data, in which case the na.strings= argument 
 can be used to tell R how missing data are specified.
 
 You can convert the data to numeric as described in FAQ 7.10
 
   -thomas
 
I think the problem can be that you use read.csv2(), which expect a 
comma (,) as decimal-indicator (as is common in Scandinavia), and a 
semi-colon (;) as separator between columns. Either you should try 
read.csv(), or you can try read.csv2(example.csv, dec=., header=TRUE)

Have a look at ?read.csv (read.csv2 is in the same help-text).

Ivar

__
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] reading csv-data

2005-06-17 Thread Don MacQueen
In my experience, this has always been due to the presence of 
non-numeric values in the input.

In the example you show, it is not obvious that there is any. I would 
start by first inspecting the input file very carefully, using a text 
editor outside of R. Since your example appears to have only one 
column of data, you could try reading it with the scan() function. 
This might produce additional information that would help you 
identify any non-numeric data. Using count.fields() on the data file 
might reveal something.

If Mean1 is an element of data, then simply typing Mean1 at the 
prompt should produce a not found message. Yet Mean1 was found. 
Have you omitted something in your email, or is there another object 
named Mean1?

-Don

At 4:50 PM +0300 6/17/05, Johanna Sundvik wrote:
Hi!

I have had this problem for a long time. I have tried to study the manuals and
search the mailing lists, but I can not solve this. I think there 
has to be one
simple solution to this, but I just can not find it.

I have saved the data in excel (csv-format). Then I read the data in R e.g.

data - read.csv2(example.csv, header=TRUE)

I look the data and it looks ok. E.g

data
  Mean1  
1   4.4332 
2   8.5113 
3  35.1624
4   9.1693
52.974
6  65.1578
7  43.2241
8   3.1278
9   5.3364
10  3.9767

However, this Mean1 is categorical when it should be real numbers.

  Mean1
[1] 4.4332  8.5113  35.1624 9.1693  2.974   65.1578 43.2241 3.1278  5.3364
Levels: 2.974 3.1278 35.1624 4.4332 43.2241 5.3364 65.1578 8.5113 9.1693

Why R does not understand that this should be real numbers? What am I doing
wrong here? Thanks for your help.

Regards,
Johanna Sundvik

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] reading csv-data

2005-06-17 Thread Spencer Graves
  I've struggled with this myself in the past.  I've recently started 
using the following:

File - pair.txt
# File name with path if different from getwd()
readLines(File, n=9)

  The function  readLines reads the first n lines as n individual 
character strings.  From this, you can identify extra headers, the 
separate characters, etc.  Then I can do something like the following:

plot(count.fields(File, sep=\t))

  The function count.fields also has arguments to specify a number of 
lines to skip before it starts to process the file, which can be helpful 
with multiple headers.  After count.fields produces a constant result 
consistent with what I want, then I'm ready to use read.table or one 
of its variants like read.csv2.

  hope this helps.
  spencer graves

Don MacQueen wrote:

 In my experience, this has always been due to the presence of 
 non-numeric values in the input.
 
 In the example you show, it is not obvious that there is any. I would 
 start by first inspecting the input file very carefully, using a text 
 editor outside of R. Since your example appears to have only one 
 column of data, you could try reading it with the scan() function. 
 This might produce additional information that would help you 
 identify any non-numeric data. Using count.fields() on the data file 
 might reveal something.
 
 If Mean1 is an element of data, then simply typing Mean1 at the 
 prompt should produce a not found message. Yet Mean1 was found. 
 Have you omitted something in your email, or is there another object 
 named Mean1?
 
 -Don
 
 At 4:50 PM +0300 6/17/05, Johanna Sundvik wrote:
 
Hi!

I have had this problem for a long time. I have tried to study the manuals and
search the mailing lists, but I can not solve this. I think there 
has to be one
simple solution to this, but I just can not find it.

I have saved the data in excel (csv-format). Then I read the data in R e.g.


data - read.csv2(example.csv, header=TRUE)

I look the data and it looks ok. E.g


data

 Mean1  
1   4.4332 
2   8.5113 
3  35.1624
4   9.1693
52.974
6  65.1578
7  43.2241
8   3.1278
9   5.3364
10  3.9767

However, this Mean1 is categorical when it should be real numbers.


 Mean1

[1] 4.4332  8.5113  35.1624 9.1693  2.974   65.1578 43.2241 3.1278  5.3364
Levels: 2.974 3.1278 35.1624 4.4332 43.2241 5.3364 65.1578 8.5113 9.1693

Why R does not understand that this should be real numbers? What am I doing
wrong here? Thanks for your help.

Regards,
Johanna Sundvik

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html