Re: [R] Read excel specific column

2022-08-23 Thread Rui Barradas

Hello,

The examples below use packages readxl and cellranger.


# to read the 1st column of a xlsx file named filename:
library(readxl)

read_xlsx(filename, range = cellranger::cell_cols("A"))

# to read 1st column of all files in filenames_vec
# result is a list of data.frames each of them with
# one column only
gene_names_list <- lapply(filenames_vec, \(x) {
  read_xlsx(x, range = cellranger::cell_cols("A"))
})

# to read 1st column of all files in filenames_vec
# result is a vector
gene_names_vec <- lapply(filenames_vec, \(x) {
  read_xlsx(x, range = cellranger::cell_cols("A"))[[1]]
})
gene_names_vec <- unlist(gene_names_vec)



If the files are xls, not xlsx, use read_xls; if you don't know, 
read_excel will call the right function.



Hope this helps,

Rui Barradas


Às 00:49 de 24/08/2022, Anas Jamshed escreveu:

I have .xlsx files with gene names in first column.How can read and load in
R?

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read excel specific column

2022-08-23 Thread Andrew Simmons
I like package openxlsx, with the function openxlsx::read.xlsx()

Another common package that people use readxl

On Tue., Aug. 23, 2022, 7:51 p.m. Anas Jamshed, 
wrote:

> I have .xlsx files with gene names in first column.How can read and load in
> R?
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read excel specific column

2022-08-23 Thread Anas Jamshed
I have .xlsx files with gene names in first column.How can read and load in
R?

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Jeff Reichman
Bill

 

So I understand that’s just unzipping the file to a temporary dir which then 
would allow read_fst to access the file directly .

 

Jeff

 

From: Bill Dunlap  
Sent: Wednesday, June 9, 2021 1:43 PM
To: reichm...@sbcglobal.net
Cc: Jan van der Laan ; r-help@r-project.org
Subject: Re: [R] Read fst files

 

Try using unzip(zipfile, files="desiredFile", exdir=tf<-tempfile()), not 
unz(zipfile, "desiredFile"), to copy the desired file from the zip file to a 
temporary location and use read_fst(tf) to read the desired file.

 

-Bill

 

On Wed, Jun 9, 2021 at 11:27 AM Jeff Reichman mailto:reichm...@sbcglobal.net> > wrote:

Jan

Makes sense. Its just that I often receive  large zip files that contain a 
variety of file types.

Jef

-Original Message-
From: R-help mailto:r-help-boun...@r-project.org> > On Behalf Of Jan van der Laan
Sent: Wednesday, June 9, 2021 12:56 PM
To: r-help@r-project.org <mailto:r-help@r-project.org> 
Subject: Re: [R] Read fst files



read_fst is from the package fst. The fileformat fst uses is a binary 
format designed to be fast readable. It is a column  oriented format and 
compressed. So, to be able to work fst needs access to the file itself 
and wont accept a file connection as functions like read.table an 
variants accept.

Also, because it is a binary compressed format using a compression 
method that is fast to read, compressing also to zip seems to defeat the 
purpose of fst.

HTH,
Jan


On 09-06-2021 15:28, Duncan Murdoch wrote:
> On 09/06/2021 9:12 a.m., Jeff Reichman wrote:
>> Duncan
>>
>> Yea that will work. It appears to be related to setting my working 
>> dir, for what ever reason neither seem to work
>> (1) knitr::opts_knit$set(root.dir 
>> ="~/My_Reference_Library/Regression") # from R Notebook or
>> (2) 
>> setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression") # 
>> from R chunk
>>
>> So it appears I can either (as you suggested) use two steps or combine 
>> but I need to enter the full path. Why other file types don't seem to 
>> need the full path ?
> 
> You need to read the documentation for read_fst() to find what it needs. 
>   If it doesn't explain this, then you should report the issue to its 
> author.
> 
>>
>> myObject <- 
>> read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip",
>>  
>> filename = "myFile.fst"))
>>
>> Thank you. I guess just one of those R things
> 
> No, it's a read_fst() thing.
> 
> Duncan Murdoch
> 
> __
> R-help@r-project.org <mailto:R-help@r-project.org>  mailing list -- To 
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org <mailto:R-help@r-project.org>  mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org <mailto:R-help@r-project.org>  mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Duncan Murdoch

On 09/06/2021 1:55 p.m., Jan van der Laan wrote:



read_fst is from the package fst. The fileformat fst uses is a binary
format designed to be fast readable. It is a column  oriented format and
compressed. So, to be able to work fst needs access to the file itself
and wont accept a file connection as functions like read.table an
variants accept.


Thanks for the info.  I think it is possible to handle such a file in a 
binary connection, but doing that in C/C++ would be kind of horrible, so 
I can understand your choice.


Duncan Murdoch



Also, because it is a binary compressed format using a compression
method that is fast to read, compressing also to zip seems to defeat the
purpose of fst.

HTH,
Jan


On 09-06-2021 15:28, Duncan Murdoch wrote:

On 09/06/2021 9:12 a.m., Jeff Reichman wrote:

Duncan

Yea that will work. It appears to be related to setting my working
dir, for what ever reason neither seem to work
(1) knitr::opts_knit$set(root.dir
="~/My_Reference_Library/Regression") # from R Notebook or
(2)
setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression") #
from R chunk

So it appears I can either (as you suggested) use two steps or combine
but I need to enter the full path. Why other file types don't seem to
need the full path ?


You need to read the documentation for read_fst() to find what it needs.
   If it doesn't explain this, then you should report the issue to its
author.



myObject <-
read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip",
filename = "myFile.fst"))

Thank you. I guess just one of those R things


No, it's a read_fst() thing.

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Bill Dunlap
Try using unzip(zipfile, files="desiredFile", exdir=tf<-tempfile()), not
unz(zipfile, "desiredFile"), to copy the desired file from the zip file to
a temporary location and use read_fst(tf) to read the desired file.

-Bill

On Wed, Jun 9, 2021 at 11:27 AM Jeff Reichman 
wrote:

> Jan
>
> Makes sense. Its just that I often receive  large zip files that contain a
> variety of file types.
>
> Jef
>
> -Original Message-
> From: R-help  On Behalf Of Jan van der Laan
> Sent: Wednesday, June 9, 2021 12:56 PM
> To: r-help@r-project.org
> Subject: Re: [R] Read fst files
>
>
>
> read_fst is from the package fst. The fileformat fst uses is a binary
> format designed to be fast readable. It is a column  oriented format and
> compressed. So, to be able to work fst needs access to the file itself
> and wont accept a file connection as functions like read.table an
> variants accept.
>
> Also, because it is a binary compressed format using a compression
> method that is fast to read, compressing also to zip seems to defeat the
> purpose of fst.
>
> HTH,
> Jan
>
>
> On 09-06-2021 15:28, Duncan Murdoch wrote:
> > On 09/06/2021 9:12 a.m., Jeff Reichman wrote:
> >> Duncan
> >>
> >> Yea that will work. It appears to be related to setting my working
> >> dir, for what ever reason neither seem to work
> >> (1) knitr::opts_knit$set(root.dir
> >> ="~/My_Reference_Library/Regression") # from R Notebook or
> >> (2)
> >> setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression") #
> >> from R chunk
> >>
> >> So it appears I can either (as you suggested) use two steps or combine
> >> but I need to enter the full path. Why other file types don't seem to
> >> need the full path ?
> >
> > You need to read the documentation for read_fst() to find what it needs.
> >   If it doesn't explain this, then you should report the issue to its
> > author.
> >
> >>
> >> myObject <-
> >>
> read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip",
>
> >> filename = "myFile.fst"))
> >>
> >> Thank you. I guess just one of those R things
> >
> > No, it's a read_fst() thing.
> >
> > Duncan Murdoch
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Jeff Newmiller
... but if you are receiving multiple-file zips then you should not be using 
unz() the way you are in your original post.

I have to agree with other responders suggesting that you handle unzipping fst 
zips manually rather than as part of an R one-liner.

On June 9, 2021 11:26:34 AM PDT, Jeff Reichman  wrote:
>Jan
>
>Makes sense. Its just that I often receive  large zip files that
>contain a variety of file types.
>
>Jef
>
>-Original Message-
>From: R-help  On Behalf Of Jan van der
>Laan
>Sent: Wednesday, June 9, 2021 12:56 PM
>To: r-help@r-project.org
>Subject: Re: [R] Read fst files
>
>
>
>read_fst is from the package fst. The fileformat fst uses is a binary 
>format designed to be fast readable. It is a column  oriented format
>and 
>compressed. So, to be able to work fst needs access to the file itself 
>and wont accept a file connection as functions like read.table an 
>variants accept.
>
>Also, because it is a binary compressed format using a compression 
>method that is fast to read, compressing also to zip seems to defeat
>the 
>purpose of fst.
>
>HTH,
>Jan
>
>
>On 09-06-2021 15:28, Duncan Murdoch wrote:
>> On 09/06/2021 9:12 a.m., Jeff Reichman wrote:
>>> Duncan
>>>
>>> Yea that will work. It appears to be related to setting my working 
>>> dir, for what ever reason neither seem to work
>>> (1) knitr::opts_knit$set(root.dir 
>>> ="~/My_Reference_Library/Regression") # from R Notebook or
>>> (2) 
>>> setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression")
># 
>>> from R chunk
>>>
>>> So it appears I can either (as you suggested) use two steps or
>combine 
>>> but I need to enter the full path. Why other file types don't seem
>to 
>>> need the full path ?
>> 
>> You need to read the documentation for read_fst() to find what it
>needs. 
>>   If it doesn't explain this, then you should report the issue to its
>
>> author.
>> 
>>>
>>> myObject <- 
>>>
>read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip",
>
>>> filename = "myFile.fst"))
>>>
>>> Thank you. I guess just one of those R things
>> 
>> No, it's a read_fst() thing.
>> 
>> Duncan Murdoch
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Jeff Reichman
Jan

Makes sense. Its just that I often receive  large zip files that contain a 
variety of file types.

Jef

-Original Message-
From: R-help  On Behalf Of Jan van der Laan
Sent: Wednesday, June 9, 2021 12:56 PM
To: r-help@r-project.org
Subject: Re: [R] Read fst files



read_fst is from the package fst. The fileformat fst uses is a binary 
format designed to be fast readable. It is a column  oriented format and 
compressed. So, to be able to work fst needs access to the file itself 
and wont accept a file connection as functions like read.table an 
variants accept.

Also, because it is a binary compressed format using a compression 
method that is fast to read, compressing also to zip seems to defeat the 
purpose of fst.

HTH,
Jan


On 09-06-2021 15:28, Duncan Murdoch wrote:
> On 09/06/2021 9:12 a.m., Jeff Reichman wrote:
>> Duncan
>>
>> Yea that will work. It appears to be related to setting my working 
>> dir, for what ever reason neither seem to work
>> (1) knitr::opts_knit$set(root.dir 
>> ="~/My_Reference_Library/Regression") # from R Notebook or
>> (2) 
>> setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression") # 
>> from R chunk
>>
>> So it appears I can either (as you suggested) use two steps or combine 
>> but I need to enter the full path. Why other file types don't seem to 
>> need the full path ?
> 
> You need to read the documentation for read_fst() to find what it needs. 
>   If it doesn't explain this, then you should report the issue to its 
> author.
> 
>>
>> myObject <- 
>> read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip",
>>  
>> filename = "myFile.fst"))
>>
>> Thank you. I guess just one of those R things
> 
> No, it's a read_fst() thing.
> 
> Duncan Murdoch
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Jan van der Laan




read_fst is from the package fst. The fileformat fst uses is a binary 
format designed to be fast readable. It is a column  oriented format and 
compressed. So, to be able to work fst needs access to the file itself 
and wont accept a file connection as functions like read.table an 
variants accept.


Also, because it is a binary compressed format using a compression 
method that is fast to read, compressing also to zip seems to defeat the 
purpose of fst.


HTH,
Jan


On 09-06-2021 15:28, Duncan Murdoch wrote:

On 09/06/2021 9:12 a.m., Jeff Reichman wrote:

Duncan

Yea that will work. It appears to be related to setting my working 
dir, for what ever reason neither seem to work
(1) knitr::opts_knit$set(root.dir 
="~/My_Reference_Library/Regression") # from R Notebook or
(2) 
setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression") # 
from R chunk


So it appears I can either (as you suggested) use two steps or combine 
but I need to enter the full path. Why other file types don't seem to 
need the full path ?


You need to read the documentation for read_fst() to find what it needs. 
  If it doesn't explain this, then you should report the issue to its 
author.




myObject <- 
read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip", 
filename = "myFile.fst"))


Thank you. I guess just one of those R things


No, it's a read_fst() thing.

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Duncan Murdoch

On 09/06/2021 9:12 a.m., Jeff Reichman wrote:

Duncan

Yea that will work. It appears to be related to setting my working dir, for 
what ever reason neither seem to work
(1) knitr::opts_knit$set(root.dir ="~/My_Reference_Library/Regression") # from 
R Notebook or
(2) setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression") # from 
R chunk

So it appears I can either (as you suggested) use two steps or combine but I 
need to enter the full path. Why other file types don't seem to need the full 
path ?


You need to read the documentation for read_fst() to find what it needs. 
 If it doesn't explain this, then you should report the issue to its 
author.




myObject <- 
read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip", 
filename = "myFile.fst"))

Thank you. I guess just one of those R things


No, it's a read_fst() thing.

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Jeff Reichman
Duncan

Yea that will work. It appears to be related to setting my working dir, for 
what ever reason neither seem to work
(1) knitr::opts_knit$set(root.dir ="~/My_Reference_Library/Regression") # from 
R Notebook or
(2) setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression") # from 
R chunk

So it appears I can either (as you suggested) use two steps or combine but I 
need to enter the full path. Why other file types don't seem to need the full 
path ?

myObject <- 
read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip",
 filename = "myFile.fst"))

Thank you. I guess just one of those R things

Jeff



-Original Message-
From: Duncan Murdoch  
Sent: Wednesday, June 9, 2021 7:27 AM
To: reichm...@sbcglobal.net; 'Eric Berger' 
Cc: 'R mailing list' 
Subject: Re: [R] Read fst files

It looks as though read_fst wants a filename, not a connection.

You should do it in two steps:

  unzip("Dataset.zip", files = "myFile.fst")
  myObject <- read_fst("myFile.fst")

This is obviously untested; you didn't even say what package read_fst() comes 
from.

Duncan Murdoch

On 09/06/2021 8:18 a.m., Jeff Reichman wrote:
> Eric
> 
>   
> 
> Typo on my point.
> 
>   
> 
> setwd("C:/Users/reichmaj/Documents/My_Reference_Library /Regression")
> 
> myObject <- read_fst(unz("Dataset.zip", filename = "myFile.fst")) # 
> read fst file
> 
>   
> 
> Error in path.expand(path) : invalid 'path' argument
> 
>   
> 
> So then I tried
> 
>   
> 
> myObject <- 
> read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library 
> /Regression /Dataset.zip", filename = "myFile.fst"))
> 
>   
> 
> Error in path.expand(path) : invalid 'path' argument
> 
>   
> 
> Error in the path??
> 
>   
> 
> Because this works just fine
> 
>   
> 
> myObject <- 
> read.csv(unz("C:/Users/reichmaj/Documents/My_Reference_Library 
> /Regression /Dataset.zip", filename = "myFile.csv"))
> 
>   
> 
> My only though is I can’t use the two function s together when dealing with 
> fst files ??
> 
>   
> 
> From: Eric Berger 
> Sent: Wednesday, June 9, 2021 3:50 AM
> To: reichm...@sbcglobal.net
> Cc: R mailing list 
> Subject: Re: [R] Read fst files
> 
>   
> 
> You are missing the second closing parenthesis. This is what the error 
> message is telling you.
> 
>   
> 
>   
> 
> On Wed, Jun 9, 2021 at 2:44 AM Jeff Reichman  <mailto:reichm...@sbcglobal.net> > wrote:
> 
> R-Help Forum
> 
> 
> 
> Anyone know why the following line of code would error out:  myObject 
> <- read_fst(unz("Dataset.zip", filename = "filename.fst"))
> 
> 
> 
> Error: Incomplete expression: filename <- read_fst(unz("Dataset.zip", 
> filename = "filename.fst")
> 
> 
> 
> I often use similar code with *.csv files in a zipped folder. For example:
> myObject <- read.csv(unz("Dataset.zip", filename = "filename.csv")), 
> which works just fine.
> 
> 
> 
> Jeff Reichman
> 
> 
> 
> 
>  [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org <mailto:R-help@r-project.org>  mailing list -- To 
> UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Duncan Murdoch

It looks as though read_fst wants a filename, not a connection.

You should do it in two steps:

 unzip("Dataset.zip", files = "myFile.fst")
 myObject <- read_fst("myFile.fst")

This is obviously untested; you didn't even say what package read_fst() 
comes from.


Duncan Murdoch

On 09/06/2021 8:18 a.m., Jeff Reichman wrote:

Eric

  


Typo on my point.

  


setwd("C:/Users/reichmaj/Documents/My_Reference_Library /Regression")

myObject <- read_fst(unz("Dataset.zip", filename = "myFile.fst")) # read fst 
file

  


Error in path.expand(path) : invalid 'path' argument

  


So then I tried

  


myObject <- read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library /Regression 
/Dataset.zip", filename = "myFile.fst"))

  


Error in path.expand(path) : invalid 'path' argument

  


Error in the path??

  


Because this works just fine

  


myObject <- read.csv(unz("C:/Users/reichmaj/Documents/My_Reference_Library /Regression 
/Dataset.zip", filename = "myFile.csv"))

  


My only though is I can’t use the two function s together when dealing with fst 
files ??

  


From: Eric Berger 
Sent: Wednesday, June 9, 2021 3:50 AM
To: reichm...@sbcglobal.net
Cc: R mailing list 
Subject: Re: [R] Read fst files

  


You are missing the second closing parenthesis. This is what the error message 
is telling you.

  

  


On Wed, Jun 9, 2021 at 2:44 AM Jeff Reichman mailto:reichm...@sbcglobal.net> > wrote:

R-Help Forum



Anyone know why the following line of code would error out:  myObject <-
read_fst(unz("Dataset.zip", filename = "filename.fst"))



Error: Incomplete expression: filename <- read_fst(unz("Dataset.zip",
filename = "filename.fst")



I often use similar code with *.csv files in a zipped folder. For example:
myObject <- read.csv(unz("Dataset.zip", filename = "filename.csv")), which
works just fine.



Jeff Reichman




 [[alternative HTML version deleted]]

__
R-help@r-project.org <mailto:R-help@r-project.org>  mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Eric Berger
Even if ultimately you want to use the functions together, for debugging
the problem you should split them into two, as in

a <- unz("C:/Users/reichmaj/Documents/My_Reference_Library /Regression
/Dataset.zip", filename = "myFile.fst")
See if that works, and examine 'a'.

And once that is working

read_fst(a)

to see what that does.

Let us know.


On Wed, Jun 9, 2021 at 3:18 PM Jeff Reichman 
wrote:

> Eric
>
>
>
> Typo on my point.
>
>
>
> setwd("C:/Users/reichmaj/Documents/My_Reference_Library /Regression")
>
> myObject <- read_fst(unz("Dataset.zip", filename = "myFile.fst")) # read
> fst file
>
>
>
> Error in path.expand(path) : invalid 'path' argument
>
>
>
> So then I tried
>
>
>
> myObject <- read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library
> /Regression /Dataset.zip", filename = "myFile.fst"))
>
>
>
> Error in path.expand(path) : invalid 'path' argument
>
>
>
> Error in the path??
>
>
>
> Because this works just fine
>
>
>
> myObject <- read.csv(unz("C:/Users/reichmaj/Documents/My_Reference_Library
> /Regression /Dataset.zip", filename = "myFile.csv"))
>
>
>
> My only though is I can’t use the two function s together when dealing
> with fst files ??
>
>
>
> *From:* Eric Berger 
> *Sent:* Wednesday, June 9, 2021 3:50 AM
> *To:* reichm...@sbcglobal.net
> *Cc:* R mailing list 
> *Subject:* Re: [R] Read fst files
>
>
>
> You are missing the second closing parenthesis. This is what the error
> message is telling you.
>
>
>
>
>
> On Wed, Jun 9, 2021 at 2:44 AM Jeff Reichman 
> wrote:
>
> R-Help Forum
>
>
>
> Anyone know why the following line of code would error out:  myObject <-
> read_fst(unz("Dataset.zip", filename = "filename.fst"))
>
>
>
> Error: Incomplete expression: filename <- read_fst(unz("Dataset.zip",
> filename = "filename.fst")
>
>
>
> I often use similar code with *.csv files in a zipped folder. For example:
> myObject <- read.csv(unz("Dataset.zip", filename = "filename.csv")), which
> works just fine.
>
>
>
> Jeff Reichman
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Jeff Reichman
Eric

 

Typo on my point. 

 

setwd("C:/Users/reichmaj/Documents/My_Reference_Library /Regression")

myObject <- read_fst(unz("Dataset.zip", filename = "myFile.fst")) # read fst 
file

 

Error in path.expand(path) : invalid 'path' argument

 

So then I tried

 

myObject <- read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library 
/Regression /Dataset.zip", filename = "myFile.fst"))

 

Error in path.expand(path) : invalid 'path' argument

 

Error in the path??

 

Because this works just fine

 

myObject <- read.csv(unz("C:/Users/reichmaj/Documents/My_Reference_Library 
/Regression /Dataset.zip", filename = "myFile.csv"))

 

My only though is I can’t use the two function s together when dealing with fst 
files ??

 

From: Eric Berger  
Sent: Wednesday, June 9, 2021 3:50 AM
To: reichm...@sbcglobal.net
Cc: R mailing list 
Subject: Re: [R] Read fst files

 

You are missing the second closing parenthesis. This is what the error message 
is telling you.

 

 

On Wed, Jun 9, 2021 at 2:44 AM Jeff Reichman mailto:reichm...@sbcglobal.net> > wrote:

R-Help Forum



Anyone know why the following line of code would error out:  myObject <-
read_fst(unz("Dataset.zip", filename = "filename.fst"))



Error: Incomplete expression: filename <- read_fst(unz("Dataset.zip",
filename = "filename.fst") 



I often use similar code with *.csv files in a zipped folder. For example:
myObject <- read.csv(unz("Dataset.zip", filename = "filename.csv")), which
works just fine.



Jeff Reichman




[[alternative HTML version deleted]]

__
R-help@r-project.org <mailto:R-help@r-project.org>  mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read fst files

2021-06-09 Thread Eric Berger
You are missing the second closing parenthesis. This is what the error
message is telling you.


On Wed, Jun 9, 2021 at 2:44 AM Jeff Reichman 
wrote:

> R-Help Forum
>
>
>
> Anyone know why the following line of code would error out:  myObject <-
> read_fst(unz("Dataset.zip", filename = "filename.fst"))
>
>
>
> Error: Incomplete expression: filename <- read_fst(unz("Dataset.zip",
> filename = "filename.fst")
>
>
>
> I often use similar code with *.csv files in a zipped folder. For example:
> myObject <- read.csv(unz("Dataset.zip", filename = "filename.csv")), which
> works just fine.
>
>
>
> Jeff Reichman
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read fst files

2021-06-08 Thread Jeff Reichman
R-Help Forum

 

Anyone know why the following line of code would error out:  myObject <-
read_fst(unz("Dataset.zip", filename = "filename.fst"))

 

Error: Incomplete expression: filename <- read_fst(unz("Dataset.zip",
filename = "filename.fst") 

 

I often use similar code with *.csv files in a zipped folder. For example:
myObject <- read.csv(unz("Dataset.zip", filename = "filename.csv")), which
works just fine.

 

Jeff Reichman

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread jim holtman
This gives the desired output:

> library(tidyverse)
> text <-  "x1  x2  x3 x4\n1 B12 \n2   C23 \n322 B32  D34 \n4   
>  D44 \n51 D53\n60 D62 "
>
> # read in the data as characters and split to a list
> input <- str_split(str_trim(read_lines(text)), ' +')
>
> max_cols <- 4  # assume a max of 4 columns
>
> put data in the correct column
> x_matrix <- do.call(rbind, map(input, ~{
+   result <- character(max_cols)
+   result[1] <- .x[1]
+   for (i in 2:length(.x)){
+ result[as.integer(str_sub(.x[i], -1))] <- .x[i]
+   }
+   result
+ }))
>
> # now add commas to convert to CSV
> x_csv <- apply(x_matrix, 1, paste, collapse = ',')
>
> # now read in and create desired output
> read_csv(x_csv)
# A tibble: 6 x 4
 x1 x2x3x4
 
1 1 B12 
2 2   C23   
3   322 B32 D34
4 4 D44
551   D53   
660 D62 
>



Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Feb 22, 2021 at 6:20 PM Avi Gross via R-help
 wrote:
>
> This discussion is a bit weird so can we step back.
>
> Someone wants help on how to read in a file that apparently was not written
> following one of several consistent sets of rules.
>
> If it was fixed width, R has functions that can read that.
>
> If it was separated by commas, tabs, single spaces, arbitrary whitespace,
> with or without a header line, we have functions that can read that if
> properly called.
>
> ALL the above normally assume that all the resulting columns are the same
> length. If any are meant to be shorter, you still leave the separators in
> place and put some NA or similar into the result. And, the functions we
> normally talk about do NOT read in and produce multiple vectors but
> something like a data.frame.
>
> So the choice is either to make sure the darn data is in a consistent
> format, or try a different plan. Fair enough?
>
> Some are suggesting parsing it yourself line by line. Certainly that can be
> done. But unless you know some schema to help you disambiguate, what do you
> do it you reach a row that is too short and has enough data for two columns.
> Which of the columns do you assign it to? If you had a clear rule, ...
>
> And what if you have different data types? R does not handle that within a
> single vector or row of a data.frame, albeit it can if you make it a list
> column.
>
> If this data is a one-time thing, perhaps it should be copied into something
> like EXCEL by a human and edited so every column is filled as you wish and
> THEN saved as something like a CSV file and then it can happily be imported
> the usual way, including NA values as needed.
>
> If the person really wants 4 independent vectors of different lengths to
> read in, there are plenty of ways to do that and no need to lump them in
> this odd format.
>
>
>
> -Original Message-
> From: R-help  On Behalf Of jim holtman
> Sent: Monday, February 22, 2021 9:01 PM
> To: Jeff Newmiller 
> Cc: r-help@R-project.org (r-help@r-project.org) 
> Subject: Re: [R] Read
>
> It looks like we can look at the last digit of the data and that would be
> the column number; is that correct?
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
> On Mon, Feb 22, 2021 at 5:34 PM Jeff Newmiller 
> wrote:
> >
> > This gets it into a data frame. If you know which columns should be
> numeric you can convert them.
> >
> > s <-
> > "x1  x2  x3 x4
> > 1 B22
> > 2 C33
> > 322 B22  D34
> > 4 D44
> > 51 D53
> > 60 D62
> > "
> >
> > tc <- textConnection( s )
> > lns <- readLines(tc)
> > close(tc)
> > if ( "" == lns[ length( lns ) ] )
> >   lns <- lns[ -length( lns ) ]
> >
> > L <- strsplit( lns, " +" )
> > m <- do.call( rbind, lapply( L[-1], function(v) if
> > (length(v) > ) else v ) ) colnames( m ) <- L[[1]] result <- as.data.frame( m,
> > stringsAsFactors = FALSE ) result
> >
> > On February 22, 2021 4:42:57 PM PST, Val  wrote:
> > >That is my problem. The spacing between columns is not consistent.
> > &g

Re: [R] Read

2021-02-22 Thread Avi Gross via R-help
This discussion is a bit weird so can we step back.

Someone wants help on how to read in a file that apparently was not written
following one of several consistent sets of rules.

If it was fixed width, R has functions that can read that.

If it was separated by commas, tabs, single spaces, arbitrary whitespace,
with or without a header line, we have functions that can read that if
properly called.

ALL the above normally assume that all the resulting columns are the same
length. If any are meant to be shorter, you still leave the separators in
place and put some NA or similar into the result. And, the functions we
normally talk about do NOT read in and produce multiple vectors but
something like a data.frame.

So the choice is either to make sure the darn data is in a consistent
format, or try a different plan. Fair enough?

Some are suggesting parsing it yourself line by line. Certainly that can be
done. But unless you know some schema to help you disambiguate, what do you
do it you reach a row that is too short and has enough data for two columns.
Which of the columns do you assign it to? If you had a clear rule, ...

And what if you have different data types? R does not handle that within a
single vector or row of a data.frame, albeit it can if you make it a list
column.

If this data is a one-time thing, perhaps it should be copied into something
like EXCEL by a human and edited so every column is filled as you wish and
THEN saved as something like a CSV file and then it can happily be imported
the usual way, including NA values as needed. 

If the person really wants 4 independent vectors of different lengths to
read in, there are plenty of ways to do that and no need to lump them in
this odd format.



-Original Message-
From: R-help  On Behalf Of jim holtman
Sent: Monday, February 22, 2021 9:01 PM
To: Jeff Newmiller 
Cc: r-help@R-project.org (r-help@r-project.org) 
Subject: Re: [R] Read

It looks like we can look at the last digit of the data and that would be
the column number; is that correct?

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Feb 22, 2021 at 5:34 PM Jeff Newmiller 
wrote:
>
> This gets it into a data frame. If you know which columns should be
numeric you can convert them.
>
> s <-
> "x1  x2  x3 x4
> 1 B22
> 2 C33
> 322 B22  D34
> 4 D44
> 51 D53
> 60 D62
> "
>
> tc <- textConnection( s )
> lns <- readLines(tc)
> close(tc)
> if ( "" == lns[ length( lns ) ] )
>   lns <- lns[ -length( lns ) ]
>
> L <- strsplit( lns, " +" )
> m <- do.call( rbind, lapply( L[-1], function(v) if 
> (length(v) ) else v ) ) colnames( m ) <- L[[1]] result <- as.data.frame( m, 
> stringsAsFactors = FALSE ) result
>
> On February 22, 2021 4:42:57 PM PST, Val  wrote:
> >That is my problem. The spacing between columns is not consistent.  
> >It
> >  may be  single space  or multiple spaces (two or three).
> >
> >On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
> >
> >wrote:
> >>
> >> You said the column values were separated by space characters.
> >> Copying the text from gmail shows that some column names and column 
> >> values are separated by single spaces (e.g., between x1 and x2) and 
> >> some by multiple spaces (e.g., between x3 and x4.  Did the mail 
> >> mess up the spacing or is there some other way to tell where the 
> >> omitted values are?
> >>
> >> -Bill
> >>
> >> On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
> >> >
> >> > I Tried that one and it did not work. Please see the error message
> >> > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> >> > \n322 B32  D34 \n4D44 \n51 D53\n60 D62
> >",
> >> > :
> >> >   more columns than column names
> >> >
> >> > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap
> > wrote:
> >> > >
> >> > > Since the columns in the file are separated by a space 
> >> > > character,
> >" ",
> >> > > add the read.table argument sep=" ".
> >> > >
> >> > > -Bill
> >> > >
> >> > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> >> > > >
> >> > > > Hi all, I am trying to read a messy data  but facing
> >difficulty.  The
> >> > > > data has several columns separated by blank space(s).  Each
&

Re: [R] Read

2021-02-22 Thread jim holtman
It looks like we can look at the last digit of the data and that would
be the column number; is that correct?

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Feb 22, 2021 at 5:34 PM Jeff Newmiller  wrote:
>
> This gets it into a data frame. If you know which columns should be numeric 
> you can convert them.
>
> s <-
> "x1  x2  x3 x4
> 1 B22
> 2 C33
> 322 B22  D34
> 4 D44
> 51 D53
> 60 D62
> "
>
> tc <- textConnection( s )
> lns <- readLines(tc)
> close(tc)
> if ( "" == lns[ length( lns ) ] )
>   lns <- lns[ -length( lns ) ]
>
> L <- strsplit( lns, " +" )
> m <- do.call( rbind, lapply( L[-1], function(v) if (length(v) c( v, rep(NA, length(L[[1]]) - length(v) ) ) else v ) )
> colnames( m ) <- L[[1]]
> result <- as.data.frame( m, stringsAsFactors = FALSE )
> result
>
> On February 22, 2021 4:42:57 PM PST, Val  wrote:
> >That is my problem. The spacing between columns is not consistent.  It
> >  may be  single space  or multiple spaces (two or three).
> >
> >On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
> >wrote:
> >>
> >> You said the column values were separated by space characters.
> >> Copying the text from gmail shows that some column names and column
> >> values are separated by single spaces (e.g., between x1 and x2) and
> >> some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
> >> up the spacing or is there some other way to tell where the omitted
> >> values are?
> >>
> >> -Bill
> >>
> >> On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
> >> >
> >> > I Tried that one and it did not work. Please see the error message
> >> > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> >> > \n322 B32  D34 \n4D44 \n51 D53\n60 D62
> >",
> >> > :
> >> >   more columns than column names
> >> >
> >> > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap
> > wrote:
> >> > >
> >> > > Since the columns in the file are separated by a space character,
> >" ",
> >> > > add the read.table argument sep=" ".
> >> > >
> >> > > -Bill
> >> > >
> >> > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> >> > > >
> >> > > > Hi all, I am trying to read a messy data  but facing
> >difficulty.  The
> >> > > > data has several columns separated by blank space(s).  Each
> >column
> >> > > > value may have different lengths across the rows.   The first
> >> > > > row(header) has four columns. However, each row may not have
> >the four
> >> > > > column values.  For instance, the first data row has only the
> >first
> >> > > > two column values. The fourth data row has the first and last
> >column
> >> > > > values, the second and the third column values are missing for
> >this
> >> > > > row..  How do I read this data set correctly? Here is my sample
> >data
> >> > > > set, output and desired output.   To make it clear to each data
> >point
> >> > > > I have added the row and column numbers. I cannot use fixed
> >width
> >> > > > format reading because each row  may have different length for
> >a
> >> > > > given column.
> >> > > >
> >> > > > dat<-read.table(text="x1  x2  x3 x4
> >> > > > 1 B22
> >> > > > 2 C33
> >> > > > 322 B22  D34
> >> > > > 4 D44
> >> > > > 51 D53
> >> > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> >> > > >
> >> > > > Output
> >> > > >   x1  x2 x3 x4
> >> > > > 1   1 B12  NA
> >> > > > 2   2C23   NA
> >> > > > 3 322  B32  D34   NA
> >> > > > 4   4   D44NA
> >> > > > 5  51 D53 NA
> >> > > > 6  60 D62NA
> >> > > >
> >> > > >
> >> > > > Desired output
> >> > > >x1   x2 x3   x4
> >> > > > 1   1B22   NA
> >> > > > 2   2 C33 NA
> >> > > > 3 322  B32NA  D34
> >> > > > 4   4  NA  D44
> >> > > > 5  51D53 NA
> >> > > > 6  60   D62  NA
> >> > > >
> >> > > > Thank you,
> >> > > >
> >> > > > __
> >> > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more,
> >see
> >> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > > > PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >> > > > and provide commented, minimal, self-contained, reproducible
> >code.
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https:

Re: [R] Read

2021-02-22 Thread Jeff Newmiller
This gets it into a data frame. If you know which columns should be numeric you 
can convert them.

s <- 
"x1  x2  x3 x4
1 B22
2 C33
322 B22  D34
4 D44
51 D53
60 D62
"

tc <- textConnection( s )
lns <- readLines(tc)
close(tc)
if ( "" == lns[ length( lns ) ] )
  lns <- lns[ -length( lns ) ]

L <- strsplit( lns, " +" )
m <- do.call( rbind, lapply( L[-1], function(v) if (length(v) wrote:
>That is my problem. The spacing between columns is not consistent.  It
>  may be  single space  or multiple spaces (two or three).
>
>On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
>wrote:
>>
>> You said the column values were separated by space characters.
>> Copying the text from gmail shows that some column names and column
>> values are separated by single spaces (e.g., between x1 and x2) and
>> some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
>> up the spacing or is there some other way to tell where the omitted
>> values are?
>>
>> -Bill
>>
>> On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>> >
>> > I Tried that one and it did not work. Please see the error message
>> > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
>> > \n322 B32  D34 \n4D44 \n51 D53\n60 D62
>",
>> > :
>> >   more columns than column names
>> >
>> > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap
> wrote:
>> > >
>> > > Since the columns in the file are separated by a space character,
>" ",
>> > > add the read.table argument sep=" ".
>> > >
>> > > -Bill
>> > >
>> > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>> > > >
>> > > > Hi all, I am trying to read a messy data  but facing 
>difficulty.  The
>> > > > data has several columns separated by blank space(s).  Each
>column
>> > > > value may have different lengths across the rows.   The first
>> > > > row(header) has four columns. However, each row may not have
>the four
>> > > > column values.  For instance, the first data row has only the
>first
>> > > > two column values. The fourth data row has the first and last
>column
>> > > > values, the second and the third column values are missing for
>this
>> > > > row..  How do I read this data set correctly? Here is my sample
>data
>> > > > set, output and desired output.   To make it clear to each data
>point
>> > > > I have added the row and column numbers. I cannot use fixed
>width
>> > > > format reading because each row  may have different length for 
>a
>> > > > given column.
>> > > >
>> > > > dat<-read.table(text="x1  x2  x3 x4
>> > > > 1 B22
>> > > > 2 C33
>> > > > 322 B22  D34
>> > > > 4 D44
>> > > > 51 D53
>> > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
>> > > >
>> > > > Output
>> > > >   x1  x2 x3 x4
>> > > > 1   1 B12  NA
>> > > > 2   2C23   NA
>> > > > 3 322  B32  D34   NA
>> > > > 4   4   D44NA
>> > > > 5  51 D53 NA
>> > > > 6  60 D62NA
>> > > >
>> > > >
>> > > > Desired output
>> > > >x1   x2 x3   x4
>> > > > 1   1B22   NA
>> > > > 2   2 C33 NA
>> > > > 3 322  B32NA  D34
>> > > > 4   4  NA  D44
>> > > > 5  51D53 NA
>> > > > 6  60   D62  NA
>> > > >
>> > > > Thank you,
>> > > >
>> > > > __
>> > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more,
>see
>> > > > https://stat.ethz.ch/mailman/listinfo/r-help
>> > > > PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>> > > > and provide commented, minimal, self-contained, reproducible
>code.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.
-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread Val
Let us take the max space is two and the output should not be fixed
filed but preferable a csv file.

On Mon, Feb 22, 2021 at 8:05 PM jim holtman  wrote:
>
> Messed up did not see your 'desired' output which will be hard since there is 
> not a consistent number of spaces that would represent the desired column 
> number.  Do you have any hit as to how to interpret the spacing especially 
> you have several hundred more lines?  Is the output supposed to the 'fixed' 
> field?
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
> On Mon, Feb 22, 2021 at 5:00 PM jim holtman  wrote:
>>
>> Try this:
>>
>> > library(tidyverse)
>>
>> > text <-  "x1  x2  x3 x4\n1 B12 \n2   C23 \n322 B32  D34 \n4
>> > D44 \n51 D53\n60 D62 "
>>
>> > # read in the data as characters and replace multiple blanks with single 
>> > blank
>> > input <- read_lines(text)
>>
>> > input <- str_replace_all(input, ' +', ' ')
>>
>> > mydata <- read_delim(input, ' ', col_names = TRUE)
>> Warning: 5 parsing failures.
>> row col  expectedactual file
>>   1  -- 4 columns 3 columns literal data
>>   2  -- 4 columns 3 columns literal data
>>   4  -- 4 columns 3 columns literal data
>>   5  -- 4 columns 2 columns literal data
>>   6  -- 4 columns 3 columns literal data
>>
>> > mydata
>> # A tibble: 6 x 4
>>  x1 x2x3x4
>>  
>> 1 1 B12   NANA
>> 2 2 C23   NANA
>> 3   322 B32   D34   NA
>> 4 4 D44   NANA
>> 551 D53   NANA
>> 660 D62   NANA
>> >
>>
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>>
>>
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>>
>>
>> On Mon, Feb 22, 2021 at 4:49 PM Val  wrote:
>>>
>>> That is my problem. The spacing between columns is not consistent.  It
>>>   may be  single space  or multiple spaces (two or three).
>>>
>>> On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap  
>>> wrote:
>>> >
>>> > You said the column values were separated by space characters.
>>> > Copying the text from gmail shows that some column names and column
>>> > values are separated by single spaces (e.g., between x1 and x2) and
>>> > some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
>>> > up the spacing or is there some other way to tell where the omitted
>>> > values are?
>>> >
>>> > -Bill
>>> >
>>> > On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>>> > >
>>> > > I Tried that one and it did not work. Please see the error message
>>> > > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
>>> > > \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
>>> > > :
>>> > >   more columns than column names
>>> > >
>>> > > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  
>>> > > wrote:
>>> > > >
>>> > > > Since the columns in the file are separated by a space character, " ",
>>> > > > add the read.table argument sep=" ".
>>> > > >
>>> > > > -Bill
>>> > > >
>>> > > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>>> > > > >
>>> > > > > Hi all, I am trying to read a messy data  but facing  difficulty.  
>>> > > > > The
>>> > > > > data has several columns separated by blank space(s).  Each column
>>> > > > > value may have different lengths across the rows.   The first
>>> > > > > row(header) has four columns. However, each row may not have the 
>>> > > > > four
>>> > > > > column values.  For instance, the first data row has only the first
>>> > > > > two column values. The fourth data row has the first and last column
>>> > > > > values, the second and the third column values are missing for this
>>> > > > > row..  How do I read this data set correctly? Here is my sample data
>>> > > > > set, output and desired output.   To make it clear to each data 
>>> > > > > point
>>> > > > > I have added the row and column numbers. I cannot use fixed width
>>> > > > > format reading because each row  may have different length for  a
>>> > > > > given column.
>>> > > > >
>>> > > > > dat<-read.table(text="x1  x2  x3 x4
>>> > > > > 1 B22
>>> > > > > 2 C33
>>> > > > > 322 B22  D34
>>> > > > > 4 D44
>>> > > > > 51 D53
>>> > > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
>>> > > > >
>>> > > > > Output
>>> > > > >   x1  x2 x3 x4
>>> > > > > 1   1 B12  NA
>>> > > > > 2   2C23   NA
>>> > > > > 3 322  B32  D34   NA
>>> > > > > 4   4   D44NA
>>> > > > > 5  51 D53 NA
>>> > > > > 6  60 D62NA
>>> > > > >
>>> > > > >
>>> > > > > Desired output
>>> > > > >x1   x2 x3   x4
>>> > > > > 1   1B22   NA
>>> > > > > 2   2 C33 NA
>>> > > > > 3 322  B32NA  D34
>>> > > > > 4   4  NA  D44
>>> > > > > 5  51D53 NA
>>> > > > > 6  60   D62

Re: [R] Read

2021-02-22 Thread jim holtman
Messed up did not see your 'desired' output which will be hard since there
is not a consistent number of spaces that would represent the desired
column number.  Do you have any hit as to how to interpret the spacing
especially you have several hundred more lines?  Is the output supposed to
the 'fixed' field?

Jim Holtman
*Data Munger Guru*


*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*


On Mon, Feb 22, 2021 at 5:00 PM jim holtman  wrote:

> Try this:
>
> > library(tidyverse)
>
> > text <-  "x1  x2  x3 x4\n1 B12 \n2   C23 \n322 B32  D34 \n4
>D44 \n51 D53\n60 D62 "
>
> > # read in the data as characters and replace multiple blanks with single
> blank
> > input <- read_lines(text)
>
> > input <- str_replace_all(input, ' +', ' ')
>
> > mydata <- read_delim(input, ' ', col_names = TRUE)
> Warning: 5 parsing failures.
> row col  expectedactual file
>   1  -- 4 columns 3 columns literal data
>   2  -- 4 columns 3 columns literal data
>   4  -- 4 columns 3 columns literal data
>   5  -- 4 columns 2 columns literal data
>   6  -- 4 columns 3 columns literal data
>
> > mydata
> # A tibble: 6 x 4
>  x1 x2x3x4
>  
> 1 1 B12   NANA
> 2 2 C23   NANA
> 3   322 B32   D34   NA
> 4 4 D44   NANA
> 551 D53   NANA
> 660 D62   NANA
> >
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
> Jim Holtman
> *Data Munger Guru*
>
>
> *What is the problem that you are trying to solve?Tell me what you want to
> do, not how you want to do it.*
>
>
> On Mon, Feb 22, 2021 at 4:49 PM Val  wrote:
>
>> That is my problem. The spacing between columns is not consistent.  It
>>   may be  single space  or multiple spaces (two or three).
>>
>> On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
>> wrote:
>> >
>> > You said the column values were separated by space characters.
>> > Copying the text from gmail shows that some column names and column
>> > values are separated by single spaces (e.g., between x1 and x2) and
>> > some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
>> > up the spacing or is there some other way to tell where the omitted
>> > values are?
>> >
>> > -Bill
>> >
>> > On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>> > >
>> > > I Tried that one and it did not work. Please see the error message
>> > > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
>> > > \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
>> > > :
>> > >   more columns than column names
>> > >
>> > > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap 
>> wrote:
>> > > >
>> > > > Since the columns in the file are separated by a space character, "
>> ",
>> > > > add the read.table argument sep=" ".
>> > > >
>> > > > -Bill
>> > > >
>> > > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>> > > > >
>> > > > > Hi all, I am trying to read a messy data  but facing
>> difficulty.  The
>> > > > > data has several columns separated by blank space(s).  Each column
>> > > > > value may have different lengths across the rows.   The first
>> > > > > row(header) has four columns. However, each row may not have the
>> four
>> > > > > column values.  For instance, the first data row has only the
>> first
>> > > > > two column values. The fourth data row has the first and last
>> column
>> > > > > values, the second and the third column values are missing for
>> this
>> > > > > row..  How do I read this data set correctly? Here is my sample
>> data
>> > > > > set, output and desired output.   To make it clear to each data
>> point
>> > > > > I have added the row and column numbers. I cannot use fixed width
>> > > > > format reading because each row  may have different length for  a
>> > > > > given column.
>> > > > >
>> > > > > dat<-read.table(text="x1  x2  x3 x4
>> > > > > 1 B22
>> > > > > 2 C33
>> > > > > 322 B22  D34
>> > > > > 4 D44
>> > > > > 51 D53
>> > > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
>> > > > >
>> > > > > Output
>> > > > >   x1  x2 x3 x4
>> > > > > 1   1 B12  NA
>> > > > > 2   2C23   NA
>> > > > > 3 322  B32  D34   NA
>> > > > > 4   4   D44NA
>> > > > > 5  51 D53 NA
>> > > > > 6  60 D62NA
>> > > > >
>> > > > >
>> > > > > Desired output
>> > > > >x1   x2 x3   x4
>> > > > > 1   1B22   NA
>> > > > > 2   2 C33 NA
>> > > > > 3 322  B32NA  D34
>> > > > > 4   4  NA  D44
>> > > > > 5  51D53 NA
>> > > > > 6  60   D62  NA
>> > > > >
>> > > > > Thank you,
>> > > > >
>> > > > > __
>> > > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > > > > https://stat.ethz.ch/mailman/listinfo/r-help
>> > > > > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>

Re: [R] Read

2021-02-22 Thread jim holtman
Try this:

> library(tidyverse)

> text <-  "x1  x2  x3 x4\n1 B12 \n2   C23 \n322 B32  D34 \n4
 D44 \n51 D53\n60 D62 "

> # read in the data as characters and replace multiple blanks with single
blank
> input <- read_lines(text)

> input <- str_replace_all(input, ' +', ' ')

> mydata <- read_delim(input, ' ', col_names = TRUE)
Warning: 5 parsing failures.
row col  expectedactual file
  1  -- 4 columns 3 columns literal data
  2  -- 4 columns 3 columns literal data
  4  -- 4 columns 3 columns literal data
  5  -- 4 columns 2 columns literal data
  6  -- 4 columns 3 columns literal data

> mydata
# A tibble: 6 x 4
 x1 x2x3x4
 
1 1 B12   NANA
2 2 C23   NANA
3   322 B32   D34   NA
4 4 D44   NANA
551 D53   NANA
660 D62   NANA
>

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
*Data Munger Guru*


*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*


On Mon, Feb 22, 2021 at 4:49 PM Val  wrote:

> That is my problem. The spacing between columns is not consistent.  It
>   may be  single space  or multiple spaces (two or three).
>
> On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap 
> wrote:
> >
> > You said the column values were separated by space characters.
> > Copying the text from gmail shows that some column names and column
> > values are separated by single spaces (e.g., between x1 and x2) and
> > some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
> > up the spacing or is there some other way to tell where the omitted
> > values are?
> >
> > -Bill
> >
> > On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
> > >
> > > I Tried that one and it did not work. Please see the error message
> > > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> > > \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
> > > :
> > >   more columns than column names
> > >
> > > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap 
> wrote:
> > > >
> > > > Since the columns in the file are separated by a space character, "
> ",
> > > > add the read.table argument sep=" ".
> > > >
> > > > -Bill
> > > >
> > > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> > > > >
> > > > > Hi all, I am trying to read a messy data  but facing  difficulty.
> The
> > > > > data has several columns separated by blank space(s).  Each column
> > > > > value may have different lengths across the rows.   The first
> > > > > row(header) has four columns. However, each row may not have the
> four
> > > > > column values.  For instance, the first data row has only the first
> > > > > two column values. The fourth data row has the first and last
> column
> > > > > values, the second and the third column values are missing for this
> > > > > row..  How do I read this data set correctly? Here is my sample
> data
> > > > > set, output and desired output.   To make it clear to each data
> point
> > > > > I have added the row and column numbers. I cannot use fixed width
> > > > > format reading because each row  may have different length for  a
> > > > > given column.
> > > > >
> > > > > dat<-read.table(text="x1  x2  x3 x4
> > > > > 1 B22
> > > > > 2 C33
> > > > > 322 B22  D34
> > > > > 4 D44
> > > > > 51 D53
> > > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> > > > >
> > > > > Output
> > > > >   x1  x2 x3 x4
> > > > > 1   1 B12  NA
> > > > > 2   2C23   NA
> > > > > 3 322  B32  D34   NA
> > > > > 4   4   D44NA
> > > > > 5  51 D53 NA
> > > > > 6  60 D62NA
> > > > >
> > > > >
> > > > > Desired output
> > > > >x1   x2 x3   x4
> > > > > 1   1B22   NA
> > > > > 2   2 C33 NA
> > > > > 3 322  B32NA  D34
> > > > > 4   4  NA  D44
> > > > > 5  51D53 NA
> > > > > 6  60   D62  NA
> > > > >
> > > > > Thank you,
> > > > >
> > > > > __
> > > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > > > > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide

Re: [R] Read

2021-02-22 Thread Val
That is my problem. The spacing between columns is not consistent.  It
  may be  single space  or multiple spaces (two or three).

On Mon, Feb 22, 2021 at 6:14 PM Bill Dunlap  wrote:
>
> You said the column values were separated by space characters.
> Copying the text from gmail shows that some column names and column
> values are separated by single spaces (e.g., between x1 and x2) and
> some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
> up the spacing or is there some other way to tell where the omitted
> values are?
>
> -Bill
>
> On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
> >
> > I Tried that one and it did not work. Please see the error message
> > Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> > \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
> > :
> >   more columns than column names
> >
> > On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  
> > wrote:
> > >
> > > Since the columns in the file are separated by a space character, " ",
> > > add the read.table argument sep=" ".
> > >
> > > -Bill
> > >
> > > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> > > >
> > > > Hi all, I am trying to read a messy data  but facing  difficulty.  The
> > > > data has several columns separated by blank space(s).  Each column
> > > > value may have different lengths across the rows.   The first
> > > > row(header) has four columns. However, each row may not have the four
> > > > column values.  For instance, the first data row has only the first
> > > > two column values. The fourth data row has the first and last column
> > > > values, the second and the third column values are missing for this
> > > > row..  How do I read this data set correctly? Here is my sample data
> > > > set, output and desired output.   To make it clear to each data point
> > > > I have added the row and column numbers. I cannot use fixed width
> > > > format reading because each row  may have different length for  a
> > > > given column.
> > > >
> > > > dat<-read.table(text="x1  x2  x3 x4
> > > > 1 B22
> > > > 2 C33
> > > > 322 B22  D34
> > > > 4 D44
> > > > 51 D53
> > > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> > > >
> > > > Output
> > > >   x1  x2 x3 x4
> > > > 1   1 B12  NA
> > > > 2   2C23   NA
> > > > 3 322  B32  D34   NA
> > > > 4   4   D44NA
> > > > 5  51 D53 NA
> > > > 6  60 D62NA
> > > >
> > > >
> > > > Desired output
> > > >x1   x2 x3   x4
> > > > 1   1B22   NA
> > > > 2   2 C33 NA
> > > > 3 322  B32NA  D34
> > > > 4   4  NA  D44
> > > > 5  51D53 NA
> > > > 6  60   D62  NA
> > > >
> > > > Thank you,
> > > >
> > > > __
> > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > PLEASE do read the posting guide 
> > > > http://www.R-project.org/posting-guide.html
> > > > and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread Bill Dunlap
You said the column values were separated by space characters.
Copying the text from gmail shows that some column names and column
values are separated by single spaces (e.g., between x1 and x2) and
some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
up the spacing or is there some other way to tell where the omitted
values are?

-Bill

On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>
> I Tried that one and it did not work. Please see the error message
> Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
> :
>   more columns than column names
>
> On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  wrote:
> >
> > Since the columns in the file are separated by a space character, " ",
> > add the read.table argument sep=" ".
> >
> > -Bill
> >
> > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> > >
> > > Hi all, I am trying to read a messy data  but facing  difficulty.  The
> > > data has several columns separated by blank space(s).  Each column
> > > value may have different lengths across the rows.   The first
> > > row(header) has four columns. However, each row may not have the four
> > > column values.  For instance, the first data row has only the first
> > > two column values. The fourth data row has the first and last column
> > > values, the second and the third column values are missing for this
> > > row..  How do I read this data set correctly? Here is my sample data
> > > set, output and desired output.   To make it clear to each data point
> > > I have added the row and column numbers. I cannot use fixed width
> > > format reading because each row  may have different length for  a
> > > given column.
> > >
> > > dat<-read.table(text="x1  x2  x3 x4
> > > 1 B22
> > > 2 C33
> > > 322 B22  D34
> > > 4 D44
> > > 51 D53
> > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> > >
> > > Output
> > >   x1  x2 x3 x4
> > > 1   1 B12  NA
> > > 2   2C23   NA
> > > 3 322  B32  D34   NA
> > > 4   4   D44NA
> > > 5  51 D53 NA
> > > 6  60 D62NA
> > >
> > >
> > > Desired output
> > >x1   x2 x3   x4
> > > 1   1B22   NA
> > > 2   2 C33 NA
> > > 3 322  B32NA  D34
> > > 4   4  NA  D44
> > > 5  51D53 NA
> > > 6  60   D62  NA
> > >
> > > Thank you,
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide 
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread Val
I Tried that one and it did not work. Please see the error message
Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
\n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
:
  more columns than column names

On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  wrote:
>
> Since the columns in the file are separated by a space character, " ",
> add the read.table argument sep=" ".
>
> -Bill
>
> On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> >
> > Hi all, I am trying to read a messy data  but facing  difficulty.  The
> > data has several columns separated by blank space(s).  Each column
> > value may have different lengths across the rows.   The first
> > row(header) has four columns. However, each row may not have the four
> > column values.  For instance, the first data row has only the first
> > two column values. The fourth data row has the first and last column
> > values, the second and the third column values are missing for this
> > row..  How do I read this data set correctly? Here is my sample data
> > set, output and desired output.   To make it clear to each data point
> > I have added the row and column numbers. I cannot use fixed width
> > format reading because each row  may have different length for  a
> > given column.
> >
> > dat<-read.table(text="x1  x2  x3 x4
> > 1 B22
> > 2 C33
> > 322 B22  D34
> > 4 D44
> > 51 D53
> > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> >
> > Output
> >   x1  x2 x3 x4
> > 1   1 B12  NA
> > 2   2C23   NA
> > 3 322  B32  D34   NA
> > 4   4   D44NA
> > 5  51 D53 NA
> > 6  60 D62NA
> >
> >
> > Desired output
> >x1   x2 x3   x4
> > 1   1B22   NA
> > 2   2 C33 NA
> > 3 322  B32NA  D34
> > 4   4  NA  D44
> > 5  51D53 NA
> > 6  60   D62  NA
> >
> > Thank you,
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2021-02-22 Thread Bill Dunlap
Since the columns in the file are separated by a space character, " ",
add the read.table argument sep=" ".

-Bill

On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>
> Hi all, I am trying to read a messy data  but facing  difficulty.  The
> data has several columns separated by blank space(s).  Each column
> value may have different lengths across the rows.   The first
> row(header) has four columns. However, each row may not have the four
> column values.  For instance, the first data row has only the first
> two column values. The fourth data row has the first and last column
> values, the second and the third column values are missing for this
> row..  How do I read this data set correctly? Here is my sample data
> set, output and desired output.   To make it clear to each data point
> I have added the row and column numbers. I cannot use fixed width
> format reading because each row  may have different length for  a
> given column.
>
> dat<-read.table(text="x1  x2  x3 x4
> 1 B22
> 2 C33
> 322 B22  D34
> 4 D44
> 51 D53
> 60 D62",header=T, fill=T,na.strings=c("","NA"))
>
> Output
>   x1  x2 x3 x4
> 1   1 B12  NA
> 2   2C23   NA
> 3 322  B32  D34   NA
> 4   4   D44NA
> 5  51 D53 NA
> 6  60 D62NA
>
>
> Desired output
>x1   x2 x3   x4
> 1   1B22   NA
> 2   2 C33 NA
> 3 322  B32NA  D34
> 4   4  NA  D44
> 5  51D53 NA
> 6  60   D62  NA
>
> Thank you,
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read

2021-02-22 Thread Val
Hi all, I am trying to read a messy data  but facing  difficulty.  The
data has several columns separated by blank space(s).  Each column
value may have different lengths across the rows.   The first
row(header) has four columns. However, each row may not have the four
column values.  For instance, the first data row has only the first
two column values. The fourth data row has the first and last column
values, the second and the third column values are missing for this
row..  How do I read this data set correctly? Here is my sample data
set, output and desired output.   To make it clear to each data point
I have added the row and column numbers. I cannot use fixed width
format reading because each row  may have different length for  a
given column.

dat<-read.table(text="x1  x2  x3 x4
1 B22
2 C33
322 B22  D34
4 D44
51 D53
60 D62",header=T, fill=T,na.strings=c("","NA"))

Output
  x1  x2 x3 x4
1   1 B12  NA
2   2C23   NA
3 322  B32  D34   NA
4   4   D44NA
5  51 D53 NA
6  60 D62NA


Desired output
   x1   x2 x3   x4
1   1B22   NA
2   2 C33 NA
3 322  B32NA  D34
4   4  NA  D44
5  51D53 NA
6  60   D62  NA

Thank you,

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read shp file

2019-11-21 Thread Michael Hannon
I can't help you locate the .shx file, but the gist of it is that a
"shapefile" actually requires a minimum of three files:

https://knowledge.autodesk.com/support/autocad-map-3d/learn-explore/caas/sfdcarticles/sfdcarticles/Required-files-that-make-up-a-shapefile.html

The .shx file is an index of the .shp file.

-- Mike

On Thu, Nov 21, 2019 at 10:44 AM Medic  wrote:
>
> Help me. pls, to read .shp file.
>
> `library("tmaptools")
> geo <- read_shape("Rom.shp", as.sf = TRUE)
> This function is deprecated and has been migrated to
> github.com/mtennekes/oldtmaptools`
>
> I have to turn to another function, but I get an unclear message
>
> `library(raster)
> geo <- shapefile ("Rus.shp")
> Error in .local(x, ...) : file.exists(extension(x, ".shx")) is not TRUE`
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read shp file

2019-11-21 Thread Medic
Help me. pls, to read .shp file.

`library("tmaptools")
geo <- read_shape("Rom.shp", as.sf = TRUE)
This function is deprecated and has been migrated to
github.com/mtennekes/oldtmaptools`

I have to turn to another function, but I get an unclear message

`library(raster)
geo <- shapefile ("Rus.shp")
Error in .local(x, ...) : file.exists(extension(x, ".shx")) is not TRUE`

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-09 Thread Val
Thank you Jeff! That was so easy command.

On Thu, Aug 8, 2019 at 11:06 PM Bert Gunter  wrote:
>
> I stand corrected!
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and 
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Aug 8, 2019 at 7:11 PM Jeff Newmiller  
> wrote:
>>
>> Val 1
>> Bert 0
>>
>> On August 8, 2019 5:22:13 PM PDT, Bert Gunter  wrote:
>> >read.table() does not have a "text" argument, so maybe you need to go
>> >back
>> >and go through a tutorial or two to learn R basics (e.g. about function
>> >calls and function arguments ?)
>> >See ?read.table  (of course)
>> >
>> >Cheers,
>> >
>> >Bert Gunter
>> >
>> >"The trouble with having an open mind is that people keep coming along
>> >and
>> >sticking things into it."
>> >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> >
>> >
>> >On Thu, Aug 8, 2019 at 5:11 PM Val  wrote:
>> >
>> >> Hi all,
>> >>
>> >> I am trying to red data where single and double quotes are embedded
>> >> in some of the fields and prevented to read the data.   As an example
>> >> please see below.
>> >>
>> >> vld<-read.table(text="name prof
>> >>   A  '4.5
>> >>   B   "3.2
>> >>   C   5.5 ",header=TRUE)
>> >>
>> >> Error in read.table(text = "name prof \n  A  '4.5\n  B
>> >> 3.2 \n  C   5.5 ",  :
>> >>   incomplete final line found by readTableHeader on 'text'
>> >>
>> >> Is there a way how to  read this data and gt the following output
>> >>   name prof
>> >> 1A  4.5
>> >> 2B  3.2
>> >> 3C  5.5
>> >>
>> >> Thank you inadvertence
>> >>
>> >> __
>> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>> >> PLEASE do read the posting guide
>> >> http://www.R-project.org/posting-guide.html
>> >> and provide commented, minimal, self-contained, reproducible code.
>> >>
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> >__
>> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >https://stat.ethz.ch/mailman/listinfo/r-help
>> >PLEASE do read the posting guide
>> >http://www.R-project.org/posting-guide.html
>> >and provide commented, minimal, self-contained, reproducible code.
>>
>> --
>> Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-08 Thread Bert Gunter
I stand corrected!

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Aug 8, 2019 at 7:11 PM Jeff Newmiller 
wrote:

> Val 1
> Bert 0
>
> On August 8, 2019 5:22:13 PM PDT, Bert Gunter 
> wrote:
> >read.table() does not have a "text" argument, so maybe you need to go
> >back
> >and go through a tutorial or two to learn R basics (e.g. about function
> >calls and function arguments ?)
> >See ?read.table  (of course)
> >
> >Cheers,
> >
> >Bert Gunter
> >
> >"The trouble with having an open mind is that people keep coming along
> >and
> >sticking things into it."
> >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> >On Thu, Aug 8, 2019 at 5:11 PM Val  wrote:
> >
> >> Hi all,
> >>
> >> I am trying to red data where single and double quotes are embedded
> >> in some of the fields and prevented to read the data.   As an example
> >> please see below.
> >>
> >> vld<-read.table(text="name prof
> >>   A  '4.5
> >>   B   "3.2
> >>   C   5.5 ",header=TRUE)
> >>
> >> Error in read.table(text = "name prof \n  A  '4.5\n  B
> >> 3.2 \n  C   5.5 ",  :
> >>   incomplete final line found by readTableHeader on 'text'
> >>
> >> Is there a way how to  read this data and gt the following output
> >>   name prof
> >> 1A  4.5
> >> 2B  3.2
> >> 3C  5.5
> >>
> >> Thank you inadvertence
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-08 Thread Jeff Newmiller
Assuming your actual case is a file containing those characters, your example R 
string has to quote them. However, it seems like you want to disable 
interpreting quotes while you read this file.

vld<-read.table(text=
"name prof
  A  '4.5
  B   \"3.2
  C   5.5 "
,header=TRUE,quote="")

(The escape character isn't really there.)

On August 8, 2019 5:40:08 PM PDT, Val  wrote:
>Thank you  all, I can read the text file but the problem was there is
>a single quote embedded  in  the first row of second column. This
>quote causes the problem
>
>vld<-read.table(text="name prof
>  A  '4.5
>  B   "3.2
>  C   5.5 ",header=TRUE)
>
>On Thu, Aug 8, 2019 at 7:24 PM Anaanthan Pillai
> wrote:
>>
>> data <- read.table(header=TRUE, text='
>>  name prof
>>   A  4.5
>>   B  3.2
>>   C  5.5
>>  ')
>> > On 9 Aug 2019, at 8:11 AM, Val  wrote:
>> >
>> > Hi all,
>> >
>> > I am trying to red data where single and double quotes are embedded
>> > in some of the fields and prevented to read the data.   As an
>example
>> > please see below.
>> >
>> > vld<-read.table(text="name prof
>> >  A  '4.5
>> >  B   "3.2
>> >  C   5.5 ",header=TRUE)
>> >
>> > Error in read.table(text = "name prof \n  A  '4.5\n  B
>> > 3.2 \n  C   5.5 ",  :
>> >  incomplete final line found by readTableHeader on 'text'
>> >
>> > Is there a way how to  read this data and gt the following output
>> >  name prof
>> > 1A  4.5
>> > 2B  3.2
>> > 3C  5.5
>> >
>> > Thank you inadvertence
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-08 Thread Jeff Newmiller
Val 1
Bert 0

On August 8, 2019 5:22:13 PM PDT, Bert Gunter  wrote:
>read.table() does not have a "text" argument, so maybe you need to go
>back
>and go through a tutorial or two to learn R basics (e.g. about function
>calls and function arguments ?)
>See ?read.table  (of course)
>
>Cheers,
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and
>sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Thu, Aug 8, 2019 at 5:11 PM Val  wrote:
>
>> Hi all,
>>
>> I am trying to red data where single and double quotes are embedded
>> in some of the fields and prevented to read the data.   As an example
>> please see below.
>>
>> vld<-read.table(text="name prof
>>   A  '4.5
>>   B   "3.2
>>   C   5.5 ",header=TRUE)
>>
>> Error in read.table(text = "name prof \n  A  '4.5\n  B
>> 3.2 \n  C   5.5 ",  :
>>   incomplete final line found by readTableHeader on 'text'
>>
>> Is there a way how to  read this data and gt the following output
>>   name prof
>> 1A  4.5
>> 2B  3.2
>> 3C  5.5
>>
>> Thank you inadvertence
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-08 Thread Peter Langfelder
I would remove the quotes using sub, something like

# Read the file as text lines
text = readLines(con = file(yourFileName))
# Remove the offending quotes
text = gsub("'|\"", "", text)
# Concatenate and turn into a data frame
concat = paste(text, collapse = "\n")
df = read.table(text = concat, ...) # Change arguments as needed

HTH,

Peter

On Thu, Aug 8, 2019 at 5:41 PM Val  wrote:
>
> Thank you  all, I can read the text file but the problem was there is
> a single quote embedded  in  the first row of second column. This
> quote causes the problem
>
> vld<-read.table(text="name prof
>   A  '4.5
>   B   "3.2
>   C   5.5 ",header=TRUE)
>
> On Thu, Aug 8, 2019 at 7:24 PM Anaanthan Pillai
>  wrote:
> >
> > data <- read.table(header=TRUE, text='
> >  name prof
> >   A  4.5
> >   B  3.2
> >   C  5.5
> >  ')
> > > On 9 Aug 2019, at 8:11 AM, Val  wrote:
> > >
> > > Hi all,
> > >
> > > I am trying to red data where single and double quotes are embedded
> > > in some of the fields and prevented to read the data.   As an example
> > > please see below.
> > >
> > > vld<-read.table(text="name prof
> > >  A  '4.5
> > >  B   "3.2
> > >  C   5.5 ",header=TRUE)
> > >
> > > Error in read.table(text = "name prof \n  A  '4.5\n  B
> > > 3.2 \n  C   5.5 ",  :
> > >  incomplete final line found by readTableHeader on 'text'
> > >
> > > Is there a way how to  read this data and gt the following output
> > >  name prof
> > > 1A  4.5
> > > 2B  3.2
> > > 3C  5.5
> > >
> > > Thank you inadvertence
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide 
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-08 Thread Val
Thank you  all, I can read the text file but the problem was there is
a single quote embedded  in  the first row of second column. This
quote causes the problem

vld<-read.table(text="name prof
  A  '4.5
  B   "3.2
  C   5.5 ",header=TRUE)

On Thu, Aug 8, 2019 at 7:24 PM Anaanthan Pillai
 wrote:
>
> data <- read.table(header=TRUE, text='
>  name prof
>   A  4.5
>   B  3.2
>   C  5.5
>  ')
> > On 9 Aug 2019, at 8:11 AM, Val  wrote:
> >
> > Hi all,
> >
> > I am trying to red data where single and double quotes are embedded
> > in some of the fields and prevented to read the data.   As an example
> > please see below.
> >
> > vld<-read.table(text="name prof
> >  A  '4.5
> >  B   "3.2
> >  C   5.5 ",header=TRUE)
> >
> > Error in read.table(text = "name prof \n  A  '4.5\n  B
> > 3.2 \n  C   5.5 ",  :
> >  incomplete final line found by readTableHeader on 'text'
> >
> > Is there a way how to  read this data and gt the following output
> >  name prof
> > 1A  4.5
> > 2B  3.2
> > 3C  5.5
> >
> > Thank you inadvertence
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-08 Thread Bert Gunter
read.table() does not have a "text" argument, so maybe you need to go back
and go through a tutorial or two to learn R basics (e.g. about function
calls and function arguments ?)
See ?read.table  (of course)

Cheers,

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Aug 8, 2019 at 5:11 PM Val  wrote:

> Hi all,
>
> I am trying to red data where single and double quotes are embedded
> in some of the fields and prevented to read the data.   As an example
> please see below.
>
> vld<-read.table(text="name prof
>   A  '4.5
>   B   "3.2
>   C   5.5 ",header=TRUE)
>
> Error in read.table(text = "name prof \n  A  '4.5\n  B
> 3.2 \n  C   5.5 ",  :
>   incomplete final line found by readTableHeader on 'text'
>
> Is there a way how to  read this data and gt the following output
>   name prof
> 1A  4.5
> 2B  3.2
> 3C  5.5
>
> Thank you inadvertence
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-08 Thread Anaanthan Pillai
data <- read.table(header=TRUE, text='
 name prof 
  A  4.5
  B  3.2
  C  5.5   
 ')
> On 9 Aug 2019, at 8:11 AM, Val  wrote:
> 
> Hi all,
> 
> I am trying to red data where single and double quotes are embedded
> in some of the fields and prevented to read the data.   As an example
> please see below.
> 
> vld<-read.table(text="name prof
>  A  '4.5
>  B   "3.2
>  C   5.5 ",header=TRUE)
> 
> Error in read.table(text = "name prof \n  A  '4.5\n  B
> 3.2 \n  C   5.5 ",  :
>  incomplete final line found by readTableHeader on 'text'
> 
> Is there a way how to  read this data and gt the following output
>  name prof
> 1A  4.5
> 2B  3.2
> 3C  5.5
> 
> Thank you inadvertence
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read

2019-08-08 Thread Thevaraja, Mayooran
Hi you can save your data file in txt or csv file. Then you can use function " 
vld <-read.table("C:/Users/ .txt",header=T)".

Regards
Mayooran

-Original Message-
From: R-help  On Behalf Of Val
Sent: Friday, 9 August 2019 12:11 PM
To: r-help@R-project.org (r-help@r-project.org) 
Subject: [R] read

Hi all,

I am trying to red data where single and double quotes are embedded
in some of the fields and prevented to read the data.   As an example
please see below.

vld<-read.table(text="name prof
  A  '4.5
  B   "3.2
  C   5.5 ",header=TRUE)

Error in read.table(text = "name prof \n  A  '4.5\n  B
3.2 \n  C   5.5 ",  :
  incomplete final line found by readTableHeader on 'text'

Is there a way how to  read this data and gt the following output
  name prof
1A  4.5
2B  3.2
3C  5.5

Thank you inadvertence

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] read

2019-08-08 Thread Val
Hi all,

I am trying to red data where single and double quotes are embedded
in some of the fields and prevented to read the data.   As an example
please see below.

vld<-read.table(text="name prof
  A  '4.5
  B   "3.2
  C   5.5 ",header=TRUE)

Error in read.table(text = "name prof \n  A  '4.5\n  B
3.2 \n  C   5.5 ",  :
  incomplete final line found by readTableHeader on 'text'

Is there a way how to  read this data and gt the following output
  name prof
1A  4.5
2B  3.2
3C  5.5

Thank you inadvertence

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-02 Thread William Dunlap via R-help
Try changing encoding="UTF-16" to fileEncoding="UTF-16".

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 1, 2019 at 9:30 PM javad bayat  wrote:

> Dear all;
> I use your suggestion but I gave the same warning messages. I changed the
> file name (Data.csv).
> "
> d4<-read.csv("./Data.csv",sep=";",header=TRUE,encoding="UTF-16")
>  Warning messages:
>  1: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>line 1 appears to contain embedded nulls
>   2: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>   line 2 appears to contain embedded nulls
>   3: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>   line 3 appears to contain embedded nulls
>   4: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>line 4 appears to contain embedded nulls
>   5: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
> line 5 appears to contain embedded nulls
>   6: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>line 1 appears to contain embedded nulls
>   7: In scan(file = file, what = what, sep = sep, quote = quote,
> dec = dec,  :
>  embedded nul(s) found in input
> "
>
> I opened the Data in notepad. This is the head of Data.csv. The columns
> have been separated by semicolons.
> "
> "INLET Time";"INLET ValueY";"TRATED WATER TANK Time";"TRATED WATER TANK
> ValueY"
> 10/28/2018;550.057861328125;10/28/2018;487.812530517578
> 10/28/2018 12:00:01 ق.ظ;550.057861328125;10/28/2018 12:00:01
> ق.ظ;487.812530517578
> 10/28/2018 12:00:02 ق.ظ;550.057861328125;10/28/2018 12:00:02
> ق.ظ;487.812530517578
> 10/28/2018 12:00:03 ق.ظ;550.057861328125;10/28/2018 12:00:03
> ق.ظ;487.812530517578
> 10/28/2018 12:00:04 ق.ظ;550.057861328125;10/28/2018 12:00:04
> ق.ظ;487.812530517578
> .
> .
> .
> "
> Thanks.
>
>
>
> On Tue, Jul 2, 2019 at 6:14 AM Jeff Newmiller 
> wrote:
>
> > Don't be so US-centric, Abby... how do you know that javad's version of
> > Excel doesn't default to using semicolons?
> >
> > ?read.csv2
> >
> > On July 1, 2019 6:06:32 PM PDT, Abby Spurdle 
> wrote:
> > >> I am trying to read an excel CSV file (1.csv). When I read it as csv
> > >file
> > >> in R, the R shows me the exact number of row. But it puts all columns
> > >in
> > >> one column, while I have 3 or 4 columns in the data frame.
> > >> d4 = read.table("./4.csv",sep=";",header=TRUE)
> > >
> > >Firstly, I recommend against naming your file "1.csv".
> > >(Start with a letter not a number).
> > >
> > >Secondly, a CSV file should be separated by commas not semicolons.
> > >You can specify sep=",", however, it's probably easier to use the
> > >read.csv() function.
> > >
> > >Note that you should be able to open your file in a text editor to see
> > >the
> > >separators.
> > >
> > >> I dont know why in the "save as type" box Unicode text (*.txt)
> > >
> > >Other posters have suggested that you need to specify the encoding.
> > >Assuming that you create your CSV file correctly in Excel, I doubt that
> > >this is necessary, but I could be wrong...
> > >
> > >Your comment suggests that you have saved your document as "Unicode
> > >text".
> > >You need to tell Excel to save the file as a CSV file.
> > >(There should be a list of save options).
> > >
> > >Simply typing a file name with a .csv file extension is unlikely to
> > >produce
> > >the desired result.
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > >__
> > >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > >https://stat.ethz.ch/mailman/listinfo/r-help
> > >PLEASE do read the posting guide
> > >http://www.R-project.org/posting-guide.html
> > >and provide commented, minimal, self-contained, reproducible code.
> >
> > --
> > Sent from my phone. Please excuse my brevity.
> >
>
>
> --
> Best Regards
> Javad Bayat
> M.Sc. Environment Engineering
> Alternative Mail: bayat...@yahoo.com
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-02 Thread Olivier Crouzet
Hi Javad,

I could not make sense of the data structure associated with the csv
file as it is copied in your previous message. Would you mind sending a
link so one can download your csv file directly (or at least the
first few lines) so people can check the exact properties of your file?

Yours.
Olivier.


On Tue, 2 Jul 2019 07:56:07 +0430 javad bayat
 wrote:

> Dear all;
> I use your suggestion but I gave the same warning messages. I changed
> the file name (Data.csv).
> "
> d4<-read.csv("./Data.csv",sep=";",header=TRUE,encoding="UTF-16")
>  Warning messages:
>  1: In read.table(file = file, header = header, sep = sep,
> quote = quote,  :
>line 1 appears to contain embedded nulls
>   2: In read.table(file = file, header = header, sep = sep,
> quote = quote,  :
>   line 2 appears to contain embedded nulls
>   3: In read.table(file = file, header = header, sep = sep,
> quote = quote,  :
>   line 3 appears to contain embedded nulls
>   4: In read.table(file = file, header = header, sep = sep,
> quote = quote,  :
>line 4 appears to contain embedded nulls
>   5: In read.table(file = file, header = header, sep = sep,
> quote = quote,  :
> line 5 appears to contain embedded nulls
>   6: In read.table(file = file, header = header, sep = sep,
> quote = quote,  :
>line 1 appears to contain embedded nulls
>   7: In scan(file = file, what = what, sep = sep, quote =
> quote, dec = dec,  :
>  embedded nul(s) found in input
> "
> 
> I opened the Data in notepad. This is the head of Data.csv. The
> columns have been separated by semicolons.
> "
> "INLET Time";"INLET ValueY";"TRATED WATER TANK Time";"TRATED WATER
> TANK ValueY"
> 10/28/2018;550.057861328125;10/28/2018;487.812530517578
> 10/28/2018 12:00:01 ق.ظ;550.057861328125;10/28/2018 12:00:01
> ق.ظ;487.812530517578
> 10/28/2018 12:00:02 ق.ظ;550.057861328125;10/28/2018 12:00:02
> ق.ظ;487.812530517578
> 10/28/2018 12:00:03 ق.ظ;550.057861328125;10/28/2018 12:00:03
> ق.ظ;487.812530517578
> 10/28/2018 12:00:04 ق.ظ;550.057861328125;10/28/2018 12:00:04
> ق.ظ;487.812530517578
> .
> .
> .
> "
> Thanks.
> 
> 
> 
> On Tue, Jul 2, 2019 at 6:14 AM Jeff Newmiller
>  wrote:
> 
> > Don't be so US-centric, Abby... how do you know that javad's
> > version of Excel doesn't default to using semicolons?
> >
> > ?read.csv2
> >
> > On July 1, 2019 6:06:32 PM PDT, Abby Spurdle 
> > wrote:
> > >> I am trying to read an excel CSV file (1.csv). When I read it as
> > >> csv
> > >file
> > >> in R, the R shows me the exact number of row. But it puts all
> > >> columns
> > >in
> > >> one column, while I have 3 or 4 columns in the data frame.
> > >> d4 = read.table("./4.csv",sep=";",header=TRUE)
> > >
> > >Firstly, I recommend against naming your file "1.csv".
> > >(Start with a letter not a number).
> > >
> > >Secondly, a CSV file should be separated by commas not semicolons.
> > >You can specify sep=",", however, it's probably easier to use the
> > >read.csv() function.
> > >
> > >Note that you should be able to open your file in a text editor to
> > >see the
> > >separators.
> > >
> > >> I dont know why in the "save as type" box Unicode text (*.txt)
> > >
> > >Other posters have suggested that you need to specify the encoding.
> > >Assuming that you create your CSV file correctly in Excel, I doubt
> > >that this is necessary, but I could be wrong...
> > >
> > >Your comment suggests that you have saved your document as "Unicode
> > >text".
> > >You need to tell Excel to save the file as a CSV file.
> > >(There should be a list of save options).
> > >
> > >Simply typing a file name with a .csv file extension is unlikely to
> > >produce
> > >the desired result.
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > >__
> > >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > >https://stat.ethz.ch/mailman/listinfo/r-help
> > >PLEASE do read the posting guide
> > >http://www.R-project.org/posting-guide.html
> > >and provide commented, minimal, self-contained, reproducible code.
> >
> > --
> > Sent from my phone. Please excuse my brevity.
> >
> 
> 
> -- 
> Best Regards
> Javad Bayat
> M.Sc. Environment Engineering
> Alternative Mail: bayat...@yahoo.com
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.


-- 
  Olivier Crouzet, PhD
  /Maître de Conférences/
  @LLING - Laboratoire de Linguistique de Nantes
UMR6310 CNRS / Université de Nantes
  /Guest Researcher/
  @UMCG (University Medical Center Groningen)
ENT department
Rijksuniversiteit Groningen

__

Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread javad bayat
Dear all;
I use your suggestion but I gave the same warning messages. I changed the
file name (Data.csv).
"
d4<-read.csv("./Data.csv",sep=";",header=TRUE,encoding="UTF-16")
 Warning messages:
 1: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
   line 1 appears to contain embedded nulls
  2: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
  line 2 appears to contain embedded nulls
  3: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
  line 3 appears to contain embedded nulls
  4: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
   line 4 appears to contain embedded nulls
  5: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
line 5 appears to contain embedded nulls
  6: In read.table(file = file, header = header, sep = sep, quote =
quote,  :
   line 1 appears to contain embedded nulls
  7: In scan(file = file, what = what, sep = sep, quote = quote,
dec = dec,  :
 embedded nul(s) found in input
"

I opened the Data in notepad. This is the head of Data.csv. The columns
have been separated by semicolons.
"
"INLET Time";"INLET ValueY";"TRATED WATER TANK Time";"TRATED WATER TANK
ValueY"
10/28/2018;550.057861328125;10/28/2018;487.812530517578
10/28/2018 12:00:01 ق.ظ;550.057861328125;10/28/2018 12:00:01
ق.ظ;487.812530517578
10/28/2018 12:00:02 ق.ظ;550.057861328125;10/28/2018 12:00:02
ق.ظ;487.812530517578
10/28/2018 12:00:03 ق.ظ;550.057861328125;10/28/2018 12:00:03
ق.ظ;487.812530517578
10/28/2018 12:00:04 ق.ظ;550.057861328125;10/28/2018 12:00:04
ق.ظ;487.812530517578
.
.
.
"
Thanks.



On Tue, Jul 2, 2019 at 6:14 AM Jeff Newmiller 
wrote:

> Don't be so US-centric, Abby... how do you know that javad's version of
> Excel doesn't default to using semicolons?
>
> ?read.csv2
>
> On July 1, 2019 6:06:32 PM PDT, Abby Spurdle  wrote:
> >> I am trying to read an excel CSV file (1.csv). When I read it as csv
> >file
> >> in R, the R shows me the exact number of row. But it puts all columns
> >in
> >> one column, while I have 3 or 4 columns in the data frame.
> >> d4 = read.table("./4.csv",sep=";",header=TRUE)
> >
> >Firstly, I recommend against naming your file "1.csv".
> >(Start with a letter not a number).
> >
> >Secondly, a CSV file should be separated by commas not semicolons.
> >You can specify sep=",", however, it's probably easier to use the
> >read.csv() function.
> >
> >Note that you should be able to open your file in a text editor to see
> >the
> >separators.
> >
> >> I dont know why in the "save as type" box Unicode text (*.txt)
> >
> >Other posters have suggested that you need to specify the encoding.
> >Assuming that you create your CSV file correctly in Excel, I doubt that
> >this is necessary, but I could be wrong...
> >
> >Your comment suggests that you have saved your document as "Unicode
> >text".
> >You need to tell Excel to save the file as a CSV file.
> >(There should be a list of save options).
> >
> >Simply typing a file name with a .csv file extension is unlikely to
> >produce
> >the desired result.
> >
> >   [[alternative HTML version deleted]]
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
>


-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread William Dunlap via R-help
If I recall correctly, Excel's 'Unicode' used to mean "UTF-16", which R's
scan() did not recognize without a hint.  The relevant argument is
fileEncoding, not encoding.  UTF-16 files generally have lots of null bytes
and UTF-8 files have no null bytes and if you try to read UTF-16 as UTF-8
you get the embedded-null warning.

I don't have Excel installed, but the following example is from R-3.5.2 on
a Linux box.

> f8 <- file(tf8 <- tempfile(), open="w", encoding="UTF-8")
> cat("\u0416;zh\n", file=f8); close(f8)
> readBin(tf8, what="raw", n=file.size(tf8))
[1] d0 96 3b 7a 68 0a
>
> f16 <- file(tf16 <- tempfile(), open="w", encoding="UTF-16")
> cat("\u0416;zh\n", file=f16); close(f16)
> readBin(tf16, what="raw", n=file.size(tf16))
 [1] ff fe 16 04 3b 00 7a 00 68 00 0a 00
>
> read.csv(tf8, sep=";", header=FALSE)
  V1 V2
1  Ж zh
> read.csv(tf16, sep=";", header=FALSE)
Error in type.convert.default(data[[i]], as.is = as.is[i], dec = dec,  :
  invalid multibyte string at ''
In addition: Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 2 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on
'/tmp/RtmpzfG6eG/file40e53389f40e'
> read.csv(tf16, sep=";", header=FALSE, fileEncoding="UTF-16")
  V1 V2
1  Ж zh
.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 1, 2019 at 8:12 PM Abby Spurdle  wrote:

> > Don't be so US-centric, Abby... how do you know that javad's version of
> Excel doesn't default to using semicolons?
>
> I don't.
>
> However, Comma-Separated Values (CSV) are, comma separated, by definition.
> So, if the files use semicolons, then...
>
> Also, the use of the wrong sep="my.delim" argument is the most likely cause
> of single column output.
>
> However, you're right, I don't really know, I'm just guessing...
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread Abby Spurdle
> Don't be so US-centric, Abby... how do you know that javad's version of
Excel doesn't default to using semicolons?

I don't.

However, Comma-Separated Values (CSV) are, comma separated, by definition.
So, if the files use semicolons, then...

Also, the use of the wrong sep="my.delim" argument is the most likely cause
of single column output.

However, you're right, I don't really know, I'm just guessing...

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread Jeff Newmiller
Don't be so US-centric, Abby... how do you know that javad's version of Excel 
doesn't default to using semicolons?

?read.csv2

On July 1, 2019 6:06:32 PM PDT, Abby Spurdle  wrote:
>> I am trying to read an excel CSV file (1.csv). When I read it as csv
>file
>> in R, the R shows me the exact number of row. But it puts all columns
>in
>> one column, while I have 3 or 4 columns in the data frame.
>> d4 = read.table("./4.csv",sep=";",header=TRUE)
>
>Firstly, I recommend against naming your file "1.csv".
>(Start with a letter not a number).
>
>Secondly, a CSV file should be separated by commas not semicolons.
>You can specify sep=",", however, it's probably easier to use the
>read.csv() function.
>
>Note that you should be able to open your file in a text editor to see
>the
>separators.
>
>> I dont know why in the "save as type" box Unicode text (*.txt)
>
>Other posters have suggested that you need to specify the encoding.
>Assuming that you create your CSV file correctly in Excel, I doubt that
>this is necessary, but I could be wrong...
>
>Your comment suggests that you have saved your document as "Unicode
>text".
>You need to tell Excel to save the file as a CSV file.
>(There should be a list of save options).
>
>Simply typing a file name with a .csv file extension is unlikely to
>produce
>the desired result.
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread Abby Spurdle
> I am trying to read an excel CSV file (1.csv). When I read it as csv file
> in R, the R shows me the exact number of row. But it puts all columns in
> one column, while I have 3 or 4 columns in the data frame.
> d4 = read.table("./4.csv",sep=";",header=TRUE)

Firstly, I recommend against naming your file "1.csv".
(Start with a letter not a number).

Secondly, a CSV file should be separated by commas not semicolons.
You can specify sep=",", however, it's probably easier to use the
read.csv() function.

Note that you should be able to open your file in a text editor to see the
separators.

> I dont know why in the "save as type" box Unicode text (*.txt)

Other posters have suggested that you need to specify the encoding.
Assuming that you create your CSV file correctly in Excel, I doubt that
this is necessary, but I could be wrong...

Your comment suggests that you have saved your document as "Unicode text".
You need to tell Excel to save the file as a CSV file.
(There should be a list of save options).

Simply typing a file name with a .csv file extension is unlikely to produce
the desired result.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread Jim Lemon
Yep, you're right.

Jim

On Tue, Jul 2, 2019 at 7:52 AM William Dunlap  wrote:
>
> Should that  encoding="UTF-8"  be  encoding="UTF-16"?
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Mon, Jul 1, 2019 at 2:45 PM Jim Lemon  wrote:
>>
>> Hi Javad,
>> Unicode characters do have embedded nulls. Try this:
>>
>> d4<-read.table("./4.csv",sep=";",header=TRUE,encoding="UTF-8")
>>
>> Jim
>>
>> On Tue, Jul 2, 2019 at 3:47 AM javad bayat  wrote:
>> >
>> > Dear R users;
>> > I am trying to read an excel CSV file (1.csv). When I read it as csv file
>> > in R, the R shows me the exact number of row. But it puts all columns in
>> > one column, while I have 3 or 4 columns in the data frame.
>> > "
>> > d4 = read.table("./4.csv",sep=";",header=TRUE)
>> >  Warning messages:
>> >  1: In read.table("./4.csv", sep = ";", header = TRUE) :
>> >   line 1 appears to contain embedded nulls
>> >  2: In read.table("./4.csv", sep = ";", header = TRUE) :
>> >  line 2 appears to contain embedded nulls
>> >  3: In read.table("./4.csv", sep = ";", header = TRUE) :
>> >  line 3 appears to contain embedded nulls
>> >  4: In read.table("./4.csv", sep = ";", header = TRUE) :
>> >  line 4 appears to contain embedded nulls
>> >  5: In read.table("./4.csv", sep = ";", header = TRUE) :
>> > line 5 appears to contain embedded nulls
>> >  6: In read.table("./4.csv", sep = ";", header = TRUE) :
>> > line 1 appears to contain embedded nulls
>> >  7: In scan(file = file, what = what, sep = sep, quote = quote, dec =
>> > dec,  :
>> >embedded nul(s) found in input
>> > > attach(d4)
>> > > dim(d4)
>> > [1] 1814394   1
>> > "
>> > I opened the csv file in excel and I tried to make a new csv (delimited)
>> > file. I dont know why in the "save as type" box Unicode text (*.txt) is
>> > written. Why the format is txt while the file extension is .CSV?
>> > Please help me to read this format correctly.
>> > Many thanks.
>> >
>> >
>> >
>> > --
>> > Best Regards
>> > Javad Bayat
>> > M.Sc. Environment Engineering
>> > Alternative Mail: bayat...@yahoo.com
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide 
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread William Dunlap via R-help
Should that  encoding="UTF-8"  be  encoding="UTF-16"?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 1, 2019 at 2:45 PM Jim Lemon  wrote:

> Hi Javad,
> Unicode characters do have embedded nulls. Try this:
>
> d4<-read.table("./4.csv",sep=";",header=TRUE,encoding="UTF-8")
>
> Jim
>
> On Tue, Jul 2, 2019 at 3:47 AM javad bayat  wrote:
> >
> > Dear R users;
> > I am trying to read an excel CSV file (1.csv). When I read it as csv file
> > in R, the R shows me the exact number of row. But it puts all columns in
> > one column, while I have 3 or 4 columns in the data frame.
> > "
> > d4 = read.table("./4.csv",sep=";",header=TRUE)
> >  Warning messages:
> >  1: In read.table("./4.csv", sep = ";", header = TRUE) :
> >   line 1 appears to contain embedded nulls
> >  2: In read.table("./4.csv", sep = ";", header = TRUE) :
> >  line 2 appears to contain embedded nulls
> >  3: In read.table("./4.csv", sep = ";", header = TRUE) :
> >  line 3 appears to contain embedded nulls
> >  4: In read.table("./4.csv", sep = ";", header = TRUE) :
> >  line 4 appears to contain embedded nulls
> >  5: In read.table("./4.csv", sep = ";", header = TRUE) :
> > line 5 appears to contain embedded nulls
> >  6: In read.table("./4.csv", sep = ";", header = TRUE) :
> > line 1 appears to contain embedded nulls
> >  7: In scan(file = file, what = what, sep = sep, quote = quote, dec =
> > dec,  :
> >embedded nul(s) found in input
> > > attach(d4)
> > > dim(d4)
> > [1] 1814394   1
> > "
> > I opened the csv file in excel and I tried to make a new csv (delimited)
> > file. I dont know why in the "save as type" box Unicode text (*.txt) is
> > written. Why the format is txt while the file extension is .CSV?
> > Please help me to read this format correctly.
> > Many thanks.
> >
> >
> >
> > --
> > Best Regards
> > Javad Bayat
> > M.Sc. Environment Engineering
> > Alternative Mail: bayat...@yahoo.com
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread Jim Lemon
Hi Javad,
Unicode characters do have embedded nulls. Try this:

d4<-read.table("./4.csv",sep=";",header=TRUE,encoding="UTF-8")

Jim

On Tue, Jul 2, 2019 at 3:47 AM javad bayat  wrote:
>
> Dear R users;
> I am trying to read an excel CSV file (1.csv). When I read it as csv file
> in R, the R shows me the exact number of row. But it puts all columns in
> one column, while I have 3 or 4 columns in the data frame.
> "
> d4 = read.table("./4.csv",sep=";",header=TRUE)
>  Warning messages:
>  1: In read.table("./4.csv", sep = ";", header = TRUE) :
>   line 1 appears to contain embedded nulls
>  2: In read.table("./4.csv", sep = ";", header = TRUE) :
>  line 2 appears to contain embedded nulls
>  3: In read.table("./4.csv", sep = ";", header = TRUE) :
>  line 3 appears to contain embedded nulls
>  4: In read.table("./4.csv", sep = ";", header = TRUE) :
>  line 4 appears to contain embedded nulls
>  5: In read.table("./4.csv", sep = ";", header = TRUE) :
> line 5 appears to contain embedded nulls
>  6: In read.table("./4.csv", sep = ";", header = TRUE) :
> line 1 appears to contain embedded nulls
>  7: In scan(file = file, what = what, sep = sep, quote = quote, dec =
> dec,  :
>embedded nul(s) found in input
> > attach(d4)
> > dim(d4)
> [1] 1814394   1
> "
> I opened the csv file in excel and I tried to make a new csv (delimited)
> file. I dont know why in the "save as type" box Unicode text (*.txt) is
> written. Why the format is txt while the file extension is .CSV?
> Please help me to read this format correctly.
> Many thanks.
>
>
>
> --
> Best Regards
> Javad Bayat
> M.Sc. Environment Engineering
> Alternative Mail: bayat...@yahoo.com
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read Unicode text (*.txt)

2019-07-01 Thread javad bayat
Dear R users;
I am trying to read an excel CSV file (1.csv). When I read it as csv file
in R, the R shows me the exact number of row. But it puts all columns in
one column, while I have 3 or 4 columns in the data frame.
"
d4 = read.table("./4.csv",sep=";",header=TRUE)
 Warning messages:
 1: In read.table("./4.csv", sep = ";", header = TRUE) :
  line 1 appears to contain embedded nulls
 2: In read.table("./4.csv", sep = ";", header = TRUE) :
 line 2 appears to contain embedded nulls
 3: In read.table("./4.csv", sep = ";", header = TRUE) :
 line 3 appears to contain embedded nulls
 4: In read.table("./4.csv", sep = ";", header = TRUE) :
 line 4 appears to contain embedded nulls
 5: In read.table("./4.csv", sep = ";", header = TRUE) :
line 5 appears to contain embedded nulls
 6: In read.table("./4.csv", sep = ";", header = TRUE) :
line 1 appears to contain embedded nulls
 7: In scan(file = file, what = what, sep = sep, quote = quote, dec =
dec,  :
   embedded nul(s) found in input
> attach(d4)
> dim(d4)
[1] 1814394   1
"
I opened the csv file in excel and I tried to make a new csv (delimited)
file. I dont know why in the "save as type" box Unicode text (*.txt) is
written. Why the format is txt while the file extension is .CSV?
Please help me to read this format correctly.
Many thanks.



-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read text files with Chinese characters

2018-12-15 Thread Patrick Giraudoux
Dear listers,

There is number of requests about reading Chinese characters from Excel 
or text files. I had to cope with the issue and wrote a small manual 
about it. It might not be an optimal solution, but at least it works :-)

One can download the pdf at: 
https://chrono-environnement.univ-fcomte.fr/personnes/annuaire/article/giraudoux-patrick?lang=en#chinese

Cheers,

Patrick



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2018-11-10 Thread Val
Thank you Jeff and all.

My data is very messy and it is nice trick suggested by Jeff to handle it

On Fri, Nov 9, 2018 at 8:42 PM Jeff Newmiller  wrote:
>
> Your file has 5 commas in the first data row, but only 4 in the header. R
> interprets this to mean your first column is intended to be row names (has
> no corresponding column label) rather than data. (Row names are "outside"
> the data frame... use str(dsh) to get a better picture.)
>
> Basically, your file does not conform to consistent practices for csv
> files of having the same number of commas in every row. If at all possible
> I would eliminate the extra comma. If you have many of these broken files,
> you might need to read the data in pieces... e.g.
>
> dsh <- read.csv( "dat.csv", header=FALSE, skip=1 )
> dsh <- dsh[ , -length( dsh ) ]
> dshh <- read.csv( "dat.csv", header=TRUE, nrow=1)
> names( dsh ) <- names( dshh )
>
> On Fri, 9 Nov 2018, Val wrote:
>
> > HI all,
> > I am trying to read a csv file, but  have a problem in the row names.
> > After reading, the name of the first column is now "row.names" and
> > all other column names are shifted to the right. The value of the last
> > column become all NAs( as an extra column).
> >
> > My sample data looks like as follow,
> > filename = dat.csv
> > The first row has a missing value at column 3 and 5. The last row has
> > a missing value at column 1 and  5
> > x1,x2,x3,x4,x5
> > 12,13,,14,,
> > 22,23,24,25,26
> > ,33,34,34,
> > To read the file I used this
> >
> > dsh<-read.csv(file="dat.csv",sep=",",row.names=NULL,fill=TRUE,header=TRUE,comment.char
> > = "", quote = "", stringsAsFactors = FALSE)
> >
> > The output  from the above  is
> > dsh
> >
> > row.names x1 x2 x3 x4 x5
> > 112 13 NA 14 NA  NA
> > 222 23 24 25 26  NA
> > 3 33 34 34 NA  NA
> >
> > The name of teh frist column is row,banes and all values of last columns is 
> > NAs
> >
> >
> > However, the desired output should be
> > x1 x2 x3 x4 x5
> > 12 13 NA 14 NA
> > 22 23 24 25 26
> > NA 33 34 34 NA
> >
> >
> > How can I fix this?
> > Thank you in advance
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  Live Go...
>Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
> ---

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2018-11-10 Thread Ista Zahn
readr::read_csv produces the desired result by default:

readr::read_csv("x1,x2,x3,x4,x5
12,13,,14,,
22,23,24,25,26
,33,34,34,")

Best,
Ista
On Fri, Nov 9, 2018 at 8:40 PM Val  wrote:
>
> HI all,
> I am trying to read a csv file, but  have a problem in the row names.
> After reading, the name of the first column is now "row.names" and
> all other column names are shifted to the right. The value of the last
> column become all NAs( as an extra column).
>
> My sample data looks like as follow,
> filename = dat.csv
> The first row has a missing value at column 3 and 5. The last row has
> a missing value at column 1 and  5
> x1,x2,x3,x4,x5
> 12,13,,14,,
> 22,23,24,25,26
> ,33,34,34,
> To read the file I used this
>
> dsh<-read.csv(file="dat.csv",sep=",",row.names=NULL,fill=TRUE,header=TRUE,comment.char
> = "", quote = "", stringsAsFactors = FALSE)
>
> The output  from the above  is
> dsh
>
>  row.names x1 x2 x3 x4 x5
> 112 13 NA 14 NA  NA
> 222 23 24 25 26  NA
> 3 33 34 34 NA  NA
>
> The name of teh frist column is row,banes and all values of last columns is 
> NAs
>
>
> However, the desired output should be
>  x1 x2 x3 x4 x5
>  12 13 NA 14 NA
>  22 23 24 25 26
>  NA 33 34 34 NA
>
>
> How can I fix this?
> Thank you in advance
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2018-11-09 Thread Rui Barradas

Hello,

I've just tested Jeff's solution, it works but the second code line 
should be


dsh <- sh[ , -length( sh ) ]


(dsh doesn't exist yet.)

Hope this helps,

Rui Barradas

Às 02:46 de 10/11/2018, Jeff Newmiller escreveu:
Your file has 5 commas in the first data row, but only 4 in the header. 
R interprets this to mean your first column is intended to be row names 
(has no corresponding column label) rather than data. (Row names are 
"outside" the data frame... use str(dsh) to get a better picture.)


Basically, your file does not conform to consistent practices for csv 
files of having the same number of commas in every row. If at all 
possible I would eliminate the extra comma. If you have many of these 
broken files, you might need to read the data in pieces... e.g.


dsh <- read.csv( "dat.csv", header=FALSE, skip=1 )
dsh <- dsh[ , -length( dsh ) ]
dshh <- read.csv( "dat.csv", header=TRUE, nrow=1)
names( dsh ) <- names( dshh )

On Fri, 9 Nov 2018, Val wrote:


HI all,
I am trying to read a csv file, but  have a problem in the row names.
After reading, the name of the first column is now "row.names" and
all other column names are shifted to the right. The value of the last
column become all NAs( as an extra column).

My sample data looks like as follow,
filename = dat.csv
The first row has a missing value at column 3 and 5. The last row has
a missing value at column 1 and  5
x1,x2,x3,x4,x5
12,13,,14,,
22,23,24,25,26
,33,34,34,
To read the file I used this

dsh<-read.csv(file="dat.csv",sep=",",row.names=NULL,fill=TRUE,header=TRUE,comment.char 


= "", quote = "", stringsAsFactors = FALSE)

The output  from the above  is
dsh

row.names x1 x2 x3 x4 x5
1    12 13 NA 14 NA  NA
2    22 23 24 25 26  NA
3 33 34 34 NA  NA

The name of teh frist column is row,banes and all values of last 
columns is NAs



However, the desired output should be
x1 x2 x3 x4 x5
12 13 NA 14 NA
22 23 24 25 26
NA 33 34 34 NA


How can I fix this?
Thank you in advance

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.



---
Jeff Newmiller    The .   .  Go Live...
DCN:    Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries    O.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read

2018-11-09 Thread Jeff Newmiller
Your file has 5 commas in the first data row, but only 4 in the header. R 
interprets this to mean your first column is intended to be row names (has 
no corresponding column label) rather than data. (Row names are "outside" 
the data frame... use str(dsh) to get a better picture.)


Basically, your file does not conform to consistent practices for csv 
files of having the same number of commas in every row. If at all possible 
I would eliminate the extra comma. If you have many of these broken files, 
you might need to read the data in pieces... e.g.


dsh <- read.csv( "dat.csv", header=FALSE, skip=1 )
dsh <- dsh[ , -length( dsh ) ]
dshh <- read.csv( "dat.csv", header=TRUE, nrow=1)
names( dsh ) <- names( dshh )

On Fri, 9 Nov 2018, Val wrote:


HI all,
I am trying to read a csv file, but  have a problem in the row names.
After reading, the name of the first column is now "row.names" and
all other column names are shifted to the right. The value of the last
column become all NAs( as an extra column).

My sample data looks like as follow,
filename = dat.csv
The first row has a missing value at column 3 and 5. The last row has
a missing value at column 1 and  5
x1,x2,x3,x4,x5
12,13,,14,,
22,23,24,25,26
,33,34,34,
To read the file I used this

dsh<-read.csv(file="dat.csv",sep=",",row.names=NULL,fill=TRUE,header=TRUE,comment.char
= "", quote = "", stringsAsFactors = FALSE)

The output  from the above  is
dsh

row.names x1 x2 x3 x4 x5
112 13 NA 14 NA  NA
222 23 24 25 26  NA
3 33 34 34 NA  NA

The name of teh frist column is row,banes and all values of last columns is NAs


However, the desired output should be
x1 x2 x3 x4 x5
12 13 NA 14 NA
22 23 24 25 26
NA 33 34 34 NA


How can I fix this?
Thank you in advance

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read

2018-11-09 Thread Val
HI all,
I am trying to read a csv file, but  have a problem in the row names.
After reading, the name of the first column is now "row.names" and
all other column names are shifted to the right. The value of the last
column become all NAs( as an extra column).

My sample data looks like as follow,
filename = dat.csv
The first row has a missing value at column 3 and 5. The last row has
a missing value at column 1 and  5
x1,x2,x3,x4,x5
12,13,,14,,
22,23,24,25,26
,33,34,34,
To read the file I used this

dsh<-read.csv(file="dat.csv",sep=",",row.names=NULL,fill=TRUE,header=TRUE,comment.char
= "", quote = "", stringsAsFactors = FALSE)

The output  from the above  is
dsh

 row.names x1 x2 x3 x4 x5
112 13 NA 14 NA  NA
222 23 24 25 26  NA
3 33 34 34 NA  NA

The name of teh frist column is row,banes and all values of last columns is NAs


However, the desired output should be
 x1 x2 x3 x4 x5
 12 13 NA 14 NA
 22 23 24 25 26
 NA 33 34 34 NA


How can I fix this?
Thank you in advance

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read txt file - date - no space

2018-08-02 Thread PIKAL Petr
Hi

Good that you have finally got desired result.
Regarding aggregate, you could consult help page

?aggregate

It has many good examples how to use it.

and for understanding factors

?factor is your friend and/or pages 16+ from R intro.

Cheers
Petr

From: Diego Avesani 
Sent: Thursday, August 2, 2018 10:53 AM
To: PIKAL Petr ; r-help mailing list 

Subject: Re: [R] read txt file - date - no space


Dear Petr,

I have read the file:
MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")

I have used  POSIXct to convert properly the date
MyData$date2<-as.POSIXct(MyData$date, format="%m/%d/%Y %H:%M")
creating a second field inside MyDate.

I have converted the -999 to NA:
MyData[MyData== -999] <- NA

dim(MyData):
160008  5
And this is clear because I have 160008 days and 5 field:
date2,date,str1,str2,str3

I have chech the structure of my data:
str(MyData)

'data.frame':   160008 obs. of  5 variables:
 $ date : Factor w/ 160008 levels "10/10/1998 0:00",..: 913 914 925 930 931 932 
933 934 935 936 ...
 $ str1 : num  0.6 0.2 0.6 0 0 0 0 0.2 0.6 0.2 ...
 $ str2 : num  0 0.2 0.2 0 0 0 0 0 0.2 0.4 ...
 $ str3 : num  0 0.2 0.4 0.6 0 0 0 0 0 0.4 ...
 $ date2: POSIXct, format: "1998-10-01 00:00:00" "1998-10-01 01:00:00" 
"1998-10-01 02:00:00" "1998-10-01 03:00:00" ...

Almost everything is clear:
str1,str2,str3 are mumbers,
date2 are date in the format according to POSIXct: Y-m-d h:m:s
date has 160008 Factor, i.e. 160008  factors which are the number of category.
I do not understand "913 914 925 930" are the possibilitiues in levels?

I have no NA in date2:

which(MyData$date2 == NA)
integer(0)

as well in date.

At this point I have applied:

daily_mean1<-aggregate(MyData$str1, list(format(MyData$date, "%Y-%m-%d")), mean)

which seems to be correct:
I have

dim(daily_mean1):
66672
str(daily_mean1)
'data.frame':   6667 obs. of  2 variables:
 $ Group.1: chr  "1998-10-01" "1998-10-02" "1998-10-03" "1998-10-04" ...
 $ x  : num  0.1667 0.0583 0.0417 0.3417 0. ...

Really Really thanks:
You not only taught me R  but also how to dealwith learning.

Can I ask you anover question about aggregate?

Again thanks

Diego

On 2 August 2018 at 10:10, PIKAL Petr 
mailto:petr.pi...@precheza.cz>> wrote:
Hi

From: Diego Avesani mailto:diego.aves...@gmail.com>>
Sent: Thursday, August 2, 2018 10:03 AM
To: PIKAL Petr mailto:petr.pi...@precheza.cz>>
Subject: Re: [R] read txt file - date - no space

Thanks,
I have just send you a e-mail, before reading this one.
Let's me read your last mail and go carefully through it.

Thanks again, really really,
I mean it

P.S.
Do you wand my *.csv file?

Not necessarily, you should better learn things yourself if you really want to 
use R. Only if after you tested all suggested ways and did not get desired 
result.

Cheers
Petr


Diego

On 2 August 2018 at 09:56, PIKAL Petr 
mailto:petr.pi...@precheza.cz>> wrote:
Well,

you followed my advice only partly. Did you get rid of your silly -999 values 
before averaging? Probably not.
Did you tried aggregating by slightly longer construction
aggregate(test[,-1], list(format(test$date, "%Y-%m-%d")), mean)
which keeps difference in month and year? Probably not.

We do not have your data, we do not know what exactly you want to do so it is 
really difficult to give you a help.

If I calculate correctly there are 24 hour in one day and you have data for 18 
years which gives me approximately 158000 distinct values.

I can get either 18 values (averaging years) or aproximately 6600 values 
(averaging days).

So my advice is:

Read your data to R
Change date column to POSIX but store it in different column
Change NA values from -999 to real NA values
Check dimension of your data ?dim
Check structure of your data ?str
Check if all dates are changed to POSIX correctly, are some of them NA?
Aggregate your values (not by lubridate function day) and store them in another 
object

Cheers
Petr


From: Diego Avesani mailto:diego.aves...@gmail.com>>
Sent: Thursday, August 2, 2018 9:31 AM
To: jim holtman mailto:jholt...@gmail.com>>; PIKAL Petr 
mailto:petr.pi...@precheza.cz>>
Cc: R mailing list mailto:r-help@r-project.org>>
Subject: Re: [R] read txt file - date - no space

Dear all,

I have found and error in the date conversion. Now it looks like:

MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
# change date to real
MyData$date<-as.POSIXct(MyData$date, format="%m/%d/%Y %H:%M")

After that I apply the PIKAL's suggestions:

aggregate(MyData[,-1], list(day(MyData$date)), mean)

And this is the final results:

 1 -82.43636 -46.12437 -319.2710
22 -82.06105 -45.74184 -319.2696
33 -82.05527 -45.52650 -319.2416
44 -82.03535 -47.59191 -319.2275

Re: [R] read txt file - date - no space

2018-08-02 Thread Diego Avesani
Dear Petr,

I have read the file:
MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")

I have used  POSIXct to convert properly the date
MyData$date2<-as.POSIXct(MyData$date, format="%m/%d/%Y %H:%M")
creating a second field inside MyDate.

I have converted the -999 to NA:
MyData[MyData== -999] <- NA

dim(MyData):
160008  5
And this is clear because I have 160008 days and 5 field:
date2,date,str1,str2,str3

I have chech the structure of my data:
str(MyData)

'data.frame': 160008 obs. of  5 variables:
 $ date : Factor w/ 160008 levels "10/10/1998 0:00",..: 913 914 925 930 931
932 933 934 935 936 ...
 $ str1 : num  0.6 0.2 0.6 0 0 0 0 0.2 0.6 0.2 ...
 $ str2 : num  0 0.2 0.2 0 0 0 0 0 0.2 0.4 ...
 $ str3 : num  0 0.2 0.4 0.6 0 0 0 0 0 0.4 ...
 $ date2: POSIXct, format: "1998-10-01 00:00:00" "1998-10-01 01:00:00"
"1998-10-01 02:00:00" "1998-10-01 03:00:00" ...

Almost everything is clear:
str1,str2,str3 are mumbers,
date2 are date in the format according to POSIXct: Y-m-d h:m:s
date has 160008 Factor, i.e. 160008  factors which are the number of
category.
I do not understand "913 914 925 930" are the possibilitiues in levels?

I have no NA in date2:

which(MyData$date2 == NA)
integer(0)

as well in date.

At this point I have applied:

daily_mean1<-aggregate(MyData$str1, list(format(MyData$date, "%Y-%m-%d")),
mean)

which seems to be correct:
I have

dim(daily_mean1):
66672
str(daily_mean1)
'data.frame': 6667 obs. of  2 variables:
 $ Group.1: chr  "1998-10-01" "1998-10-02" "1998-10-03" "1998-10-04" ...
 $ x  : num  0.1667 0.0583 0.0417 0.3417 0. ...

Really Really thanks:
You not only taught me R  but also how to dealwith learning.

Can I ask you anover question about aggregate?

Again thanks

Diego


On 2 August 2018 at 10:10, PIKAL Petr  wrote:

> Hi
>
>
>
> *From:* Diego Avesani 
> *Sent:* Thursday, August 2, 2018 10:03 AM
> *To:* PIKAL Petr 
> *Subject:* Re: [R] read txt file - date - no space
>
>
>
> Thanks,
>
> I have just send you a e-mail, before reading this one.
>
> Let's me read your last mail and go carefully through it.
>
>
>
> Thanks again, really really,
>
> I mean it
>
>
>
> P.S.
>
> Do you wand my *.csv file?
>
>
>
> Not necessarily, you should better learn things yourself if you really
> want to use R. Only if after you tested all suggested ways and did not get
> desired result.
>
>
>
> Cheers
>
> Petr
>
>
>
>
> Diego
>
>
>
> On 2 August 2018 at 09:56, PIKAL Petr  wrote:
>
> Well,
>
>
>
> you followed my advice only partly. Did you get rid of your silly -999
> values before averaging? Probably not.
>
> Did you tried aggregating by slightly longer construction
>
> aggregate(test[,-1], list(format(test$date, "%Y-%m-%d")), mean)
>
> which keeps difference in month and year? Probably not.
>
>
>
> We do not have your data, we do not know what exactly you want to do so it
> is really difficult to give you a help.
>
>
>
> If I calculate correctly there are 24 hour in one day and you have data
> for 18 years which gives me approximately 158000 distinct values.
>
>
>
> I can get either 18 values (averaging years) or aproximately 6600 values
> (averaging days).
>
>
>
> So my advice is:
>
>
>
> Read your data to R
>
> Change date column to POSIX but store it in different column
>
> Change NA values from -999 to real NA values
>
> Check dimension of your data ?dim
>
> Check structure of your data ?str
>
> Check if all dates are changed to POSIX correctly, are some of them NA?
>
> Aggregate your values (not by lubridate function day) and store them in
> another object
>
>
>
> Cheers
>
> Petr
>
>
>
>
>
> *From:* Diego Avesani 
> *Sent:* Thursday, August 2, 2018 9:31 AM
> *To:* jim holtman ; PIKAL Petr  >
> *Cc:* R mailing list 
> *Subject:* Re: [R] read txt file - date - no space
>
>
>
> Dear all,
>
>
>
> I have found and error in the date conversion. Now it looks like:
>
>
>
> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>
> # change date to real
>
> MyData$date<-as.POSIXct(MyData$date, format="%*m*/%*d*/%Y %H:%M")
>
>
>
> After that I apply the PIKAL's suggestions:
>
>
>
> aggregate(MyData[,-1], list(day(MyData$date)), mean)
>
>
>
> And this is the final results:
>
>
>
>  1 -82.43636 -46.12437 -319.2710
>
> 22 -82.06105 -45.74184 -319.2696
>
> 33 -82.05527 -45.52650 -319.241

Re: [R] read txt file - date - no space

2018-08-02 Thread Diego Avesani
Dear PIKAL, Dear all,

thanks again a lot.
I have finally understood what "in line" means.
I would definitely read some "R-intro" and in this moment I am reading a
R-tutorial.
I would not post formatted messages.

I would ask if it is possible to have some final suggestions:
- how to have daily mean;
- how to deal with NA;

Indeed, after changing the ate format I get

   Group.1  str1  str2  str3
11 -82.43636 -46.12437 -319.2710
22 -82.06105 -45.74184 -319.2696
33 -82.05527 -45.52650 -319.2416
44 -82.03535 -47.59191 -319.2275
...
31  31 -86.10234 -47.06247 -340.0968

As I said in the previously this is not correct.
This because I have not made myself clear about my purpose. As I told you
some days ago, I have a *.csv file with hourly data from 10/21/1998 to
12/31/2016.
I would like to compute the daily means.
Basically, I would like to have the mean of the hourly date for each day
from 10/21/1998 to 12/31/2016 and not 31 values.

I really really thank, especially for you patience.
I am leaning a lot,
Again thanks

Diego


On 2 August 2018 at 09:32, PIKAL Petr  wrote:

> Hi
>
>
>
> see in line (and please do not post HTML formated messages, it could be
> scrammbled)
>
>
>
> *From:* Diego Avesani 
> *Sent:* Thursday, August 2, 2018 8:56 AM
> *To:* jim holtman ; PIKAL Petr  >
> *Cc:* R mailing list 
> *Subject:* Re: [R] read txt file - date - no space
>
>
>
> Dear
>
>
>
> I have check the one of the line that gives me problem. I mean, which give
> NA after R processing. I think that is similar to the others:
>
>
>
> You should stop **thinking** and instead do real inspection of „offending“
> values.
>
>
>
> 10/12/1998 10:00,0,0,0
>
> 10/12/1998 11:00,0,0,0
>
> 10/12/1998 12:00,0,0,0
>
> 10/12/1998 13:00,0,0,0
>
> 10/12/1998 14:00,0,0,0
>
> 10/12/1998 15:00,0,0,0
>
> 10/12/1998 16:00,0,0,0
>
> 10/12/1998 17:00,0,0,0
>
>
>
> These lines do not pose any problem with formating.
>
>
>
> >  test<-read.table("clipboard", sep=",")
>
> > str(test)
>
> 'data.frame':   8 obs. of  4 variables:
>
> $ V1: Factor w/ 8 levels "10/12/1998 10:00",..: 1 2 3 4 5 6 7 8
>
> $ V2: int  0 0 0 0 0 0 0 0
>
> $ V3: int  0 0 0 0 0 0 0 0
>
> $ V4: int  0 0 0 0 0 0 0 0
>
> > as.POSIXct(test$V1, format="%d/%m/%Y %H:%M")
>
> [1] "1998-12-10 10:00:00 CET" "1998-12-10 11:00:00 CET"
>
> [3] "1998-12-10 12:00:00 CET" "1998-12-10 13:00:00 CET"
>
> [5] "1998-12-10 14:00:00 CET" "1998-12-10 15:00:00 CET"
>
> [7] "1998-12-10 16:00:00 CET" "1998-12-10 17:00:00 CET"
>
>
>
>
>
> @jim: It seems that you suggestion is focus on reading data from the
> terminal. It is possible to apply it to a *.csv file?
>
>
>
> @Pikal: Could it be that there are some date conversion error?
>
>
>
> Well, your str(MyData) result suggest, that conversion from character to
> POSIX was done correctly (at least partly).
>
>
>
> However NAs in date column you posted in second mail suggest, that some
> values in the input are probably formated differently and they are changed
> to NA during POSIX conversion.
>
>
>
> You could check which values are problematic if instead directly changing
> date column to POSIX you put a new column to you data with converted POSIX
> values
>
>
>
> So read your data from csv file and change date to POSIX but store it in
> different column of data frame.
>
>
>
> MyData$date2 <- as.POSIXct(MyData$date, format="%d/%m/%Y %H:%M")
>
>
>
> and check which values in your original file are formated differently.
>
>
>
> something like
>
> MyData$date[is.na(MyData$date2)]
>
>
>
> However your (very basic) questions suggest, that you have only minor
> understanding what are R objects, how to check, inspect and manipulate
> them. You could do a big favour to yourself going through basic
> documentation as I suggested before.
>
>
>
> Cheers
>
> Petr
>
>
>
> Thanks again,
>
> Diego
>
>
>
>
> Diego
>
>
>
> On 1 August 2018 at 17:01, jim holtman  wrote:
>
>
> Try this:
>
>
>
> > library(lubridate)
>
> > library(tidyverse)
>
> > input <- read.csv(text = "date,str1,str2,str3
>
> + 10/1/1998 0:00,0.6,0,0
>
> +   10/1/1998 1:00,0.2,0.2,0.2
>
> +   10/1/1998 2:00,0.6,0.2,0.4
>
> +   10/1/1998 3:00,0,0,0.6
>
> +   10/1/1998 4:00,0,0,0
>
> + 

Re: [R] read txt file - date - no space

2018-08-02 Thread PIKAL Petr
Well,

you followed my advice only partly. Did you get rid of your silly -999 values 
before averaging? Probably not.
Did you tried aggregating by slightly longer construction
aggregate(test[,-1], list(format(test$date, "%Y-%m-%d")), mean)
which keeps difference in month and year? Probably not.

We do not have your data, we do not know what exactly you want to do so it is 
really difficult to give you a help.

If I calculate correctly there are 24 hour in one day and you have data for 18 
years which gives me approximately 158000 distinct values.

I can get either 18 values (averaging years) or aproximately 6600 values 
(averaging days).

So my advice is:

Read your data to R
Change date column to POSIX but store it in different column
Change NA values from -999 to real NA values
Check dimension of your data ?dim
Check structure of your data ?str
Check if all dates are changed to POSIX correctly, are some of them NA?
Aggregate your values (not by lubridate function day) and store them in another 
object

Cheers
Petr


From: Diego Avesani 
Sent: Thursday, August 2, 2018 9:31 AM
To: jim holtman ; PIKAL Petr 
Cc: R mailing list 
Subject: Re: [R] read txt file - date - no space

Dear all,

I have found and error in the date conversion. Now it looks like:

MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
# change date to real
MyData$date<-as.POSIXct(MyData$date, format="%m/%d/%Y %H:%M")

After that I apply the PIKAL's suggestions:

aggregate(MyData[,-1], list(day(MyData$date)), mean)

And this is the final results:

 1 -82.43636 -46.12437 -319.2710
22 -82.06105 -45.74184 -319.2696
33 -82.05527 -45.52650 -319.2416
44 -82.03535 -47.59191 -319.2275
55 -77.44928 -50.05953 -320.5798
...
31-86.10234 -47.06247 -340.0968

However, it is not correct.
This because I have not made myself clear about my purpose. As I told you some 
days ago, I have a *.csv file with hourly data from 10/21/1998 to 12/31/2016. I 
would like to compute the daily means. Basically, I would like to have the mean 
of the hourly date for each day from 10/21/1998 to 12/31/2016 and not 31 values.

Really really thanks again,
Diego


Diego

On 2 August 2018 at 08:55, Diego Avesani 
mailto:diego.aves...@gmail.com>> wrote:
Dear

I have check the one of the line that gives me problem. I mean, which give NA 
after R processing. I think that is similar to the others:

10/12/1998 10:00,0,0,0
10/12/1998 11:00,0,0,0
10/12/1998 12:00,0,0,0
10/12/1998 13:00,0,0,0
10/12/1998 14:00,0,0,0
10/12/1998 15:00,0,0,0
10/12/1998 16:00,0,0,0
10/12/1998 17:00,0,0,0

@jim: It seems that you suggestion is focus on reading data from the terminal. 
It is possible to apply it to a *.csv file?

@Pikal: Could it be that there are some date conversion error?

Thanks again,
Diego


Diego

On 1 August 2018 at 17:01, jim holtman 
mailto:jholt...@gmail.com>> wrote:

Try this:

> library(lubridate)
> library(tidyverse)
> input <- read.csv(text = "date,str1,str2,str3
+ 10/1/1998 0:00,0.6,0,0
+   10/1/1998 1:00,0.2,0.2,0.2
+   10/1/1998 2:00,0.6,0.2,0.4
+   10/1/1998 3:00,0,0,0.6
+   10/1/1998 4:00,0,0,0
+   10/1/1998 5:00,0,0,0
+   10/1/1998 6:00,0,0,0
+   10/1/1998 7:00,0.2,0,0", as.is<http://as.is> = TRUE)
> # convert the date and add the "day" so summarize
> input <- input %>%
+   mutate(date = mdy_hm(date),
+  day = floor_date(date, unit = 'day')
+   )
>
> by_day <- input %>%
+   group_by(day) %>%
+   summarise(m_s1 = mean(str1),
+ m_s2 = mean(str2),
+ m_s3 = mean(str3)
+   )
>
> by_day
# A tibble: 1 x 4
  day  m_s1   m_s2  m_s3
   
1 1998-10-01 00:00:00 0.200 0.0500 0.150

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Tue, Jul 31, 2018 at 11:54 PM Diego Avesani 
mailto:diego.aves...@gmail.com>> wrote:
Dear all,
I am sorry, I did a lot of confusion. I am sorry, I have to relax and stat
all again in order to understand.
If I could I would like to start again, without mixing strategy and waiting
for your advice.

I am really appreciate you help, really really.
Here my new file, a *.csv file (buy the way, it is possible to attach it in
the mailing list?)

date,str1,str2,str3
10/1/1998 0:00,0.6,0,0
10/1/1998 1:00,0.2,0.2,0.2
10/1/1998 2:00,0.6,0.2,0.4
10/1/1998 3:00,0,0,0.6
10/1/1998 4:00,0,0,0
10/1/1998 5:00,0,0,0
10/1/1998 6:00,0,0,0
10/1/1998 7:00,0.2,0,0


I read it as:
MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")

at this point I would like to have the daily mean.
What would you suggest?

Really Really thanks,
You are my lifesaver

Thanks



Diego


On 1 August 2018 at 01:01

Re: [R] read txt file - date - no space

2018-08-02 Thread Diego Avesani
Dear all,

I have found and error in the date conversion. Now it looks like:

MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
# change date to real
MyData$date<-as.POSIXct(MyData$date, format="%*m*/%*d*/%Y %H:%M")

After that I apply the PIKAL's suggestions:

aggregate(MyData[,-1], list(day(MyData$date)), mean)

And this is the final results:

 1 -82.43636 -46.12437 -319.2710
22 -82.06105 -45.74184 -319.2696
33 -82.05527 -45.52650 -319.2416
44 -82.03535 -47.59191 -319.2275
55 -77.44928 -50.05953 -320.5798
...
31-86.10234 -47.06247 -340.0968

However, it is not correct.
This because I have not made myself clear about my purpose. As I told you
some days ago, I have a *.csv file with hourly data from 10/21/1998
to 12/31/2016. I would like to compute the daily means. Basically, I would
like to have the mean of the hourly date for each day from 10/21/1998
to 12/31/2016 and not 31 values.

Really really thanks again,
Diego


Diego


On 2 August 2018 at 08:55, Diego Avesani  wrote:

> Dear
>
> I have check the one of the line that gives me problem. I mean, which give
> NA after R processing. I think that is similar to the others:
>
> 10/12/1998 10:00,0,0,0
> 10/12/1998 11:00,0,0,0
> 10/12/1998 12:00,0,0,0
> 10/12/1998 13:00,0,0,0
> 10/12/1998 14:00,0,0,0
> 10/12/1998 15:00,0,0,0
> 10/12/1998 16:00,0,0,0
> 10/12/1998 17:00,0,0,0
>
> @jim: It seems that you suggestion is focus on reading data from the
> terminal. It is possible to apply it to a *.csv file?
>
> @Pikal: Could it be that there are some date conversion error?
>
> Thanks again,
> Diego
>
>
> Diego
>
>
> On 1 August 2018 at 17:01, jim holtman  wrote:
>
>>
>> Try this:
>>
>> > library(lubridate)
>> > library(tidyverse)
>> > input <- read.csv(text = "date,str1,str2,str3
>> + 10/1/1998 0:00,0.6,0,0
>> +   10/1/1998 1:00,0.2,0.2,0.2
>> +   10/1/1998 2:00,0.6,0.2,0.4
>> +   10/1/1998 3:00,0,0,0.6
>> +   10/1/1998 4:00,0,0,0
>> +   10/1/1998 5:00,0,0,0
>> +   10/1/1998 6:00,0,0,0
>> +   10/1/1998 7:00,0.2,0,0", as.is = TRUE)
>> > # convert the date and add the "day" so summarize
>> > input <- input %>%
>> +   mutate(date = mdy_hm(date),
>> +  day = floor_date(date, unit = 'day')
>> +   )
>> >
>> > by_day <- input %>%
>> +   group_by(day) %>%
>> +   summarise(m_s1 = mean(str1),
>> + m_s2 = mean(str2),
>> + m_s3 = mean(str3)
>> +   )
>> >
>> > by_day
>> # A tibble: 1 x 4
>>   day  m_s1   m_s2  m_s3
>>
>> 1 1998-10-01 00:00:00 0.200 0.0500 0.150
>>
>> Jim Holtman
>> *Data Munger Guru*
>>
>>
>> *What is the problem that you are trying to solve?Tell me what you want
>> to do, not how you want to do it.*
>>
>>
>> On Tue, Jul 31, 2018 at 11:54 PM Diego Avesani 
>> wrote:
>>
>>> Dear all,
>>> I am sorry, I did a lot of confusion. I am sorry, I have to relax and
>>> stat
>>> all again in order to understand.
>>> If I could I would like to start again, without mixing strategy and
>>> waiting
>>> for your advice.
>>>
>>> I am really appreciate you help, really really.
>>> Here my new file, a *.csv file (buy the way, it is possible to attach it
>>> in
>>> the mailing list?)
>>>
>>> date,str1,str2,str3
>>> 10/1/1998 0:00,0.6,0,0
>>> 10/1/1998 1:00,0.2,0.2,0.2
>>> 10/1/1998 2:00,0.6,0.2,0.4
>>> 10/1/1998 3:00,0,0,0.6
>>> 10/1/1998 4:00,0,0,0
>>> 10/1/1998 5:00,0,0,0
>>> 10/1/1998 6:00,0,0,0
>>> 10/1/1998 7:00,0.2,0,0
>>>
>>>
>>> I read it as:
>>> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>>>
>>> at this point I would like to have the daily mean.
>>> What would you suggest?
>>>
>>> Really Really thanks,
>>> You are my lifesaver
>>>
>>> Thanks
>>>
>>>
>>>
>>> Diego
>>>
>>>
>>> On 1 August 2018 at 01:01, Jeff Newmiller 
>>> wrote:
>>>
>>> > ... and the most common source of NA values in time data is wrong
>>> > timezones. You really need to make sure the timezone that is assumed
>>> when
>>> > the character data are converted to POSIXt agrees with the data. In
>>> most
>>> > cases the easiest way to insure this is to use
>>> >
>>> > Sys.setenv(TZ="US/Pacific")
>>> >
>>> > or whatever timezone from
>>> >
>>> > OlsonNames()
>>> >
>>> > corresponds with your data. Execute this setenv function before the
>>> > strptime or as.POSIXct() function call.
>>> >
>>> > You can use
>>> >
>>> > MyData[ is.na(MyData$datetime), ]
>>> >
>>> > to see which records are failing to convert time.
>>> >
>>> > [1] https://github.com/jdnewmil/eci298sp2016/blob/master/QuickHowto1
>>> >
>>> > On July 31, 2018 3:04:05 PM PDT, Jim Lemon 
>>> wrote:
>>> > >Hi Diego,
>>> > >I think the error is due to NA values in your data file. If I extend
>>> > >your example and run it, I get no errors:
>>> > >
>>> > >MyData<-read.table(text="103001930 103001580 103001530
>>> > >1998-10-01 00:00:00 0.6 0 0
>>> > >1998-10-01 01:00:00 0.2 0.2 0.2
>>> > >1998-10-01 02:00:00 0.6 0.

Re: [R] read txt file - date - no space

2018-08-02 Thread PIKAL Petr
Hi

see in line (and please do not post HTML formated messages, it could be 
scrammbled)

From: Diego Avesani 
Sent: Thursday, August 2, 2018 8:56 AM
To: jim holtman ; PIKAL Petr 
Cc: R mailing list 
Subject: Re: [R] read txt file - date - no space

Dear

I have check the one of the line that gives me problem. I mean, which give NA 
after R processing. I think that is similar to the others:

You should stop **thinking** and instead do real inspection of „offending“ 
values.

10/12/1998 10:00,0,0,0
10/12/1998 11:00,0,0,0
10/12/1998 12:00,0,0,0
10/12/1998 13:00,0,0,0
10/12/1998 14:00,0,0,0
10/12/1998 15:00,0,0,0
10/12/1998 16:00,0,0,0
10/12/1998 17:00,0,0,0

These lines do not pose any problem with formating.

>  test<-read.table("clipboard", sep=",")
> str(test)
'data.frame':   8 obs. of  4 variables:
$ V1: Factor w/ 8 levels "10/12/1998 10:00",..: 1 2 3 4 5 6 7 8
$ V2: int  0 0 0 0 0 0 0 0
$ V3: int  0 0 0 0 0 0 0 0
$ V4: int  0 0 0 0 0 0 0 0
> as.POSIXct(test$V1, format="%d/%m/%Y %H:%M")
[1] "1998-12-10 10:00:00 CET" "1998-12-10 11:00:00 CET"
[3] "1998-12-10 12:00:00 CET" "1998-12-10 13:00:00 CET"
[5] "1998-12-10 14:00:00 CET" "1998-12-10 15:00:00 CET"
[7] "1998-12-10 16:00:00 CET" "1998-12-10 17:00:00 CET"


@jim: It seems that you suggestion is focus on reading data from the terminal. 
It is possible to apply it to a *.csv file?

@Pikal: Could it be that there are some date conversion error?

Well, your str(MyData) result suggest, that conversion from character to POSIX 
was done correctly (at least partly).

However NAs in date column you posted in second mail suggest, that some values 
in the input are probably formated differently and they are changed to NA 
during POSIX conversion.

You could check which values are problematic if instead directly changing date 
column to POSIX you put a new column to you data with converted POSIX values

So read your data from csv file and change date to POSIX but store it in 
different column of data frame.

MyData$date2 <- as.POSIXct(MyData$date, format="%d/%m/%Y %H:%M")

and check which values in your original file are formated differently.

something like
MyData$date[is.na(MyData$date2)]

However your (very basic) questions suggest, that you have only minor 
understanding what are R objects, how to check, inspect and manipulate them. 
You could do a big favour to yourself going through basic documentation as I 
suggested before.

Cheers
Petr

Thanks again,
Diego


Diego

On 1 August 2018 at 17:01, jim holtman 
mailto:jholt...@gmail.com>> wrote:

Try this:

> library(lubridate)
> library(tidyverse)
> input <- read.csv(text = "date,str1,str2,str3
+ 10/1/1998 0:00,0.6,0,0
+   10/1/1998 1:00,0.2,0.2,0.2
+   10/1/1998 2:00,0.6,0.2,0.4
+   10/1/1998 3:00,0,0,0.6
+   10/1/1998 4:00,0,0,0
+   10/1/1998 5:00,0,0,0
+   10/1/1998 6:00,0,0,0
+   10/1/1998 7:00,0.2,0,0", as.is<http://as.is> = TRUE)
> # convert the date and add the "day" so summarize
> input <- input %>%
+   mutate(date = mdy_hm(date),
+  day = floor_date(date, unit = 'day')
+   )
>
> by_day <- input %>%
+   group_by(day) %>%
+   summarise(m_s1 = mean(str1),
+ m_s2 = mean(str2),
+ m_s3 = mean(str3)
+   )
>
> by_day
# A tibble: 1 x 4
  day  m_s1   m_s2  m_s3
   
1 1998-10-01 00:00:00 0.200 0.0500 0.150

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Tue, Jul 31, 2018 at 11:54 PM Diego Avesani 
mailto:diego.aves...@gmail.com>> wrote:
Dear all,
I am sorry, I did a lot of confusion. I am sorry, I have to relax and stat
all again in order to understand.
If I could I would like to start again, without mixing strategy and waiting
for your advice.

I am really appreciate you help, really really.
Here my new file, a *.csv file (buy the way, it is possible to attach it in
the mailing list?)

date,str1,str2,str3
10/1/1998 0:00,0.6,0,0
10/1/1998 1:00,0.2,0.2,0.2
10/1/1998 2:00,0.6,0.2,0.4
10/1/1998 3:00,0,0,0.6
10/1/1998 4:00,0,0,0
10/1/1998 5:00,0,0,0
10/1/1998 6:00,0,0,0
10/1/1998 7:00,0.2,0,0


I read it as:
MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")

at this point I would like to have the daily mean.
What would you suggest?

Really Really thanks,
You are my lifesaver

Thanks



Diego


On 1 August 2018 at 01:01, Jeff Newmiller 
mailto:jdnew...@dcn.davis.ca.us>> wrote:

> ... and the most common source of NA values in time data is wrong
> timezones. You really need to make sure the timezone that is assumed when
> the character data are converted to POSI

Re: [R] read txt file - date - no space

2018-08-01 Thread Diego Avesani
Dear

I have check the one of the line that gives me problem. I mean, which give
NA after R processing. I think that is similar to the others:

10/12/1998 10:00,0,0,0
10/12/1998 11:00,0,0,0
10/12/1998 12:00,0,0,0
10/12/1998 13:00,0,0,0
10/12/1998 14:00,0,0,0
10/12/1998 15:00,0,0,0
10/12/1998 16:00,0,0,0
10/12/1998 17:00,0,0,0

@jim: It seems that you suggestion is focus on reading data from the
terminal. It is possible to apply it to a *.csv file?

@Pikal: Could it be that there are some date conversion error?

Thanks again,
Diego


Diego


On 1 August 2018 at 17:01, jim holtman  wrote:

>
> Try this:
>
> > library(lubridate)
> > library(tidyverse)
> > input <- read.csv(text = "date,str1,str2,str3
> + 10/1/1998 0:00,0.6,0,0
> +   10/1/1998 1:00,0.2,0.2,0.2
> +   10/1/1998 2:00,0.6,0.2,0.4
> +   10/1/1998 3:00,0,0,0.6
> +   10/1/1998 4:00,0,0,0
> +   10/1/1998 5:00,0,0,0
> +   10/1/1998 6:00,0,0,0
> +   10/1/1998 7:00,0.2,0,0", as.is = TRUE)
> > # convert the date and add the "day" so summarize
> > input <- input %>%
> +   mutate(date = mdy_hm(date),
> +  day = floor_date(date, unit = 'day')
> +   )
> >
> > by_day <- input %>%
> +   group_by(day) %>%
> +   summarise(m_s1 = mean(str1),
> + m_s2 = mean(str2),
> + m_s3 = mean(str3)
> +   )
> >
> > by_day
> # A tibble: 1 x 4
>   day  m_s1   m_s2  m_s3
>
> 1 1998-10-01 00:00:00 0.200 0.0500 0.150
>
> Jim Holtman
> *Data Munger Guru*
>
>
> *What is the problem that you are trying to solve?Tell me what you want to
> do, not how you want to do it.*
>
>
> On Tue, Jul 31, 2018 at 11:54 PM Diego Avesani 
> wrote:
>
>> Dear all,
>> I am sorry, I did a lot of confusion. I am sorry, I have to relax and stat
>> all again in order to understand.
>> If I could I would like to start again, without mixing strategy and
>> waiting
>> for your advice.
>>
>> I am really appreciate you help, really really.
>> Here my new file, a *.csv file (buy the way, it is possible to attach it
>> in
>> the mailing list?)
>>
>> date,str1,str2,str3
>> 10/1/1998 0:00,0.6,0,0
>> 10/1/1998 1:00,0.2,0.2,0.2
>> 10/1/1998 2:00,0.6,0.2,0.4
>> 10/1/1998 3:00,0,0,0.6
>> 10/1/1998 4:00,0,0,0
>> 10/1/1998 5:00,0,0,0
>> 10/1/1998 6:00,0,0,0
>> 10/1/1998 7:00,0.2,0,0
>>
>>
>> I read it as:
>> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>>
>> at this point I would like to have the daily mean.
>> What would you suggest?
>>
>> Really Really thanks,
>> You are my lifesaver
>>
>> Thanks
>>
>>
>>
>> Diego
>>
>>
>> On 1 August 2018 at 01:01, Jeff Newmiller 
>> wrote:
>>
>> > ... and the most common source of NA values in time data is wrong
>> > timezones. You really need to make sure the timezone that is assumed
>> when
>> > the character data are converted to POSIXt agrees with the data. In most
>> > cases the easiest way to insure this is to use
>> >
>> > Sys.setenv(TZ="US/Pacific")
>> >
>> > or whatever timezone from
>> >
>> > OlsonNames()
>> >
>> > corresponds with your data. Execute this setenv function before the
>> > strptime or as.POSIXct() function call.
>> >
>> > You can use
>> >
>> > MyData[ is.na(MyData$datetime), ]
>> >
>> > to see which records are failing to convert time.
>> >
>> > [1] https://github.com/jdnewmil/eci298sp2016/blob/master/QuickHowto1
>> >
>> > On July 31, 2018 3:04:05 PM PDT, Jim Lemon 
>> wrote:
>> > >Hi Diego,
>> > >I think the error is due to NA values in your data file. If I extend
>> > >your example and run it, I get no errors:
>> > >
>> > >MyData<-read.table(text="103001930 103001580 103001530
>> > >1998-10-01 00:00:00 0.6 0 0
>> > >1998-10-01 01:00:00 0.2 0.2 0.2
>> > >1998-10-01 02:00:00 0.6 0.2 0.4
>> > >1998-10-01 03:00:00 0 0 0.6
>> > >1998-10-01 04:00:00 0 0 0
>> > >1998-10-01 05:00:00 0 0 0
>> > >1998-10-01 06:00:00 0 0 0
>> > >1998-10-01 07:00:00 0.2 0 0
>> > >1998-10-01 08:00:00 0.6 0 0
>> > >1998-10-01 09:00:00 0.2 0.2 0.2
>> > >1998-10-01 10:00:00 0.6 0.2 0.4
>> > >1998-10-01 11:00:00 0 0 0.6
>> > >1998-10-01 12:00:00 0 0 0
>> > >1998-10-01 13:00:00 0 0 0
>> > >1998-10-01 14:00:00 0 0 0
>> > >1998-10-01 15:00:00 0.2 0 0
>> > >1998-10-01 16:00:00 0.6 0 0
>> > >1998-10-01 17:00:00 0.2 0.2 0.2
>> > >1998-10-01 18:00:00 0.6 0.2 0.4
>> > >1998-10-01 19:00:00 0 0 0.6
>> > >1998-10-01 20:00:00 0 0 0
>> > >1998-10-01 21:00:00 0 0 0
>> > >1998-10-01 22:00:00 0 0 0
>> > >1998-10-01 23:00:00 0.2 0 0
>> > >1998-10-02 00:00:00 0.6 0 0
>> > >1998-10-02 01:00:00 0.2 0.2 0.2
>> > >1998-10-02 02:00:00 0.6 0.2 0.4
>> > >1998-10-02 03:00:00 0 0 0.6
>> > >1998-10-02 04:00:00 0 0 0
>> > >1998-10-02 05:00:00 0 0 0
>> > >1998-10-02 06:00:00 0 0 0
>> > >1998-10-02 07:00:00 0.2 0 0
>> > >1998-10-02 08:00:00 0.6 0 0
>> > >1998-10-02 09:00:00 0.2 0.2 0.2
>> > >1998-10-02 10:00:00 0.6 0.2 0.4
>> > >1998-10-02 11:00:00 0 0 0.6
>> > >1998-10-02 12:00:00 0 0 0
>> > >1998-10-02 13:00:00 0 0 0
>> > >1998-10

Re: [R] read txt file - date - no space

2018-08-01 Thread jim holtman
Try this:

> library(lubridate)
> library(tidyverse)
> input <- read.csv(text = "date,str1,str2,str3
+ 10/1/1998 0:00,0.6,0,0
+   10/1/1998 1:00,0.2,0.2,0.2
+   10/1/1998 2:00,0.6,0.2,0.4
+   10/1/1998 3:00,0,0,0.6
+   10/1/1998 4:00,0,0,0
+   10/1/1998 5:00,0,0,0
+   10/1/1998 6:00,0,0,0
+   10/1/1998 7:00,0.2,0,0", as.is = TRUE)
> # convert the date and add the "day" so summarize
> input <- input %>%
+   mutate(date = mdy_hm(date),
+  day = floor_date(date, unit = 'day')
+   )
>
> by_day <- input %>%
+   group_by(day) %>%
+   summarise(m_s1 = mean(str1),
+ m_s2 = mean(str2),
+ m_s3 = mean(str3)
+   )
>
> by_day
# A tibble: 1 x 4
  day  m_s1   m_s2  m_s3
   
1 1998-10-01 00:00:00 0.200 0.0500 0.150

Jim Holtman
*Data Munger Guru*


*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*


On Tue, Jul 31, 2018 at 11:54 PM Diego Avesani 
wrote:

> Dear all,
> I am sorry, I did a lot of confusion. I am sorry, I have to relax and stat
> all again in order to understand.
> If I could I would like to start again, without mixing strategy and waiting
> for your advice.
>
> I am really appreciate you help, really really.
> Here my new file, a *.csv file (buy the way, it is possible to attach it in
> the mailing list?)
>
> date,str1,str2,str3
> 10/1/1998 0:00,0.6,0,0
> 10/1/1998 1:00,0.2,0.2,0.2
> 10/1/1998 2:00,0.6,0.2,0.4
> 10/1/1998 3:00,0,0,0.6
> 10/1/1998 4:00,0,0,0
> 10/1/1998 5:00,0,0,0
> 10/1/1998 6:00,0,0,0
> 10/1/1998 7:00,0.2,0,0
>
>
> I read it as:
> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>
> at this point I would like to have the daily mean.
> What would you suggest?
>
> Really Really thanks,
> You are my lifesaver
>
> Thanks
>
>
>
> Diego
>
>
> On 1 August 2018 at 01:01, Jeff Newmiller 
> wrote:
>
> > ... and the most common source of NA values in time data is wrong
> > timezones. You really need to make sure the timezone that is assumed when
> > the character data are converted to POSIXt agrees with the data. In most
> > cases the easiest way to insure this is to use
> >
> > Sys.setenv(TZ="US/Pacific")
> >
> > or whatever timezone from
> >
> > OlsonNames()
> >
> > corresponds with your data. Execute this setenv function before the
> > strptime or as.POSIXct() function call.
> >
> > You can use
> >
> > MyData[ is.na(MyData$datetime), ]
> >
> > to see which records are failing to convert time.
> >
> > [1] https://github.com/jdnewmil/eci298sp2016/blob/master/QuickHowto1
> >
> > On July 31, 2018 3:04:05 PM PDT, Jim Lemon  wrote:
> > >Hi Diego,
> > >I think the error is due to NA values in your data file. If I extend
> > >your example and run it, I get no errors:
> > >
> > >MyData<-read.table(text="103001930 103001580 103001530
> > >1998-10-01 00:00:00 0.6 0 0
> > >1998-10-01 01:00:00 0.2 0.2 0.2
> > >1998-10-01 02:00:00 0.6 0.2 0.4
> > >1998-10-01 03:00:00 0 0 0.6
> > >1998-10-01 04:00:00 0 0 0
> > >1998-10-01 05:00:00 0 0 0
> > >1998-10-01 06:00:00 0 0 0
> > >1998-10-01 07:00:00 0.2 0 0
> > >1998-10-01 08:00:00 0.6 0 0
> > >1998-10-01 09:00:00 0.2 0.2 0.2
> > >1998-10-01 10:00:00 0.6 0.2 0.4
> > >1998-10-01 11:00:00 0 0 0.6
> > >1998-10-01 12:00:00 0 0 0
> > >1998-10-01 13:00:00 0 0 0
> > >1998-10-01 14:00:00 0 0 0
> > >1998-10-01 15:00:00 0.2 0 0
> > >1998-10-01 16:00:00 0.6 0 0
> > >1998-10-01 17:00:00 0.2 0.2 0.2
> > >1998-10-01 18:00:00 0.6 0.2 0.4
> > >1998-10-01 19:00:00 0 0 0.6
> > >1998-10-01 20:00:00 0 0 0
> > >1998-10-01 21:00:00 0 0 0
> > >1998-10-01 22:00:00 0 0 0
> > >1998-10-01 23:00:00 0.2 0 0
> > >1998-10-02 00:00:00 0.6 0 0
> > >1998-10-02 01:00:00 0.2 0.2 0.2
> > >1998-10-02 02:00:00 0.6 0.2 0.4
> > >1998-10-02 03:00:00 0 0 0.6
> > >1998-10-02 04:00:00 0 0 0
> > >1998-10-02 05:00:00 0 0 0
> > >1998-10-02 06:00:00 0 0 0
> > >1998-10-02 07:00:00 0.2 0 0
> > >1998-10-02 08:00:00 0.6 0 0
> > >1998-10-02 09:00:00 0.2 0.2 0.2
> > >1998-10-02 10:00:00 0.6 0.2 0.4
> > >1998-10-02 11:00:00 0 0 0.6
> > >1998-10-02 12:00:00 0 0 0
> > >1998-10-02 13:00:00 0 0 0
> > >1998-10-02 14:00:00 0 0 0
> > >1998-10-02 15:00:00 0.2 0 0
> > >1998-10-02 16:00:00 0.6 0 0
> > >1998-10-02 17:00:00 0.2 0.2 0.2
> > >1998-10-02 18:00:00 0.6 0.2 0.4
> > >1998-10-02 19:00:00 0 0 0.6
> > >1998-10-02 20:00:00 0 0 0
> > >1998-10-02 21:00:00 0 0 0
> > >1998-10-02 22:00:00 0 0 0
> > >1998-10-02 23:00:00 0.2 0 0",
> > >skip=1,stringsAsFactors=FALSE)
> > >names(MyData)<-c("date","time","st1","st2","st3")
> > >MyData$datetime<-strptime(paste(MyData$date,MyData$time),
> > > format="%Y-%m-%d %H:%M:%S")
> > >MyData$datetime
> > >st1_daily<-by(MyData$st1,MyData$date,mean)
> > >st2_daily<-by(MyData$st2,MyData$date,mean)
> > >st3_daily<-by(MyData$st3,MyData$date,mean)
> > >st1_daily
> > >st2_daily
> > >st3_daily
> > >
> > >Try adding na.rm=TRUE to the "by" calls:
> > >
> > >st1_daily<-by(

Re: [R] read txt file - date - no space

2018-08-01 Thread PIKAL Petr
Hi

see in line

From: Diego Avesani 
Sent: Wednesday, August 1, 2018 2:30 PM
To: PIKAL Petr 
Cc: r-help mailing list 
Subject: Re: [R] read txt file - date - no space

Dear Pikal, Deal all,

again really thank.

it seems not working.
Some specifications: My non data are -999, but I could change it.

You must change it to NA. How the poor R should know that -999 is missing and 
not a real value.

something like

Mydata[Mydata== -999] <- NA

should do it.

My final results is:


11  -55.86242 -55.84764660 -277.4775

22  -55.47554 -94.58921682 -277.4845

33  -55.47095 -99.20239198 -277.4709

44  -55.46470 -55.45952932 -392.9071

55  -55.43335 -55.40171682 -388.4110

66  -55.40108 -55.37399691 -332.9068

77  -55.39201 -55.35156250 -332.8902

88 -110.87184   0.16136188 -281.8230

99 -110.95077 -55.63856096 -332.9564

10  10 -157.64430  -0.06602705 -315.3840

11  11 -105.06157   0.11507675 -315.4152

12  12  -70.08677 -52.54501096 -316.7247

So it is not correct.
For example for the first day in my csv I would have expected 0.167.

I am going to post what you have suggested:

for  str(MyData)

Your data seems to be OK, so after you change your -999 to NA everything should 
be OK.

'data.frame': 160008 obs. of  4 variables:
 $ date: POSIXct, format: "1998-01-10 00:00:00" "1998-01-10 01:00:00" 
"1998-01-10 02:00:00" "1998-01-10 03:00:00" ...
 $ str1: num  0.6 0.2 0.6 0 0 0 0 0.2 0.6 0.2 ...
 $ str2: num  0 0.2 0.2 0 0 0 0 0 0.2 0.4 ...
 $ str3: num  0 0.2 0.4 0.6 0 0 0 0 0 0.4 ...

unfortunately, I am not able to post

dput(str[1:20,])

it gives me

Error in str[1:20, ] : object of type 'closure' is not subsettable



dput(MyData[1:20,])



I would recommend you to spend some time reading R-intro which should be 
located in doc/manual folder of your installation. It could help you in many 
situations.



Cheers

Petr


Thanks again,
I hope that what I posted could be enough in order to help me.



Diego

On 1 August 2018 at 13:58, PIKAL Petr 
mailto:petr.pi...@precheza.cz>> wrote:
Hi

I did not get through all answers you already got and you probably obtained 
similar advice as mine.

# read data (if you have csv file just use read.csv)
> test<-read.table("clipboard", header=T, sep=",")

# control your object(s)
> str(test)
'data.frame':   8 obs. of  4 variables:
 $ date: Factor w/ 8 levels "10/1/1998 0:00",..: 1 2 3 4 5 6 7 8
 $ str1: num  0.6 0.2 0.6 0 0 0 0 0.2
 $ str2: num  0 0.2 0.2 0 0 0 0 0
 $ str3: num  0 0.2 0.4 0.6 0 0 0 0

#if it is OK change first column to real date by POSIXct
test$date<-as.POSIXct(test$date, format="%d/%m/%Y %H:%M")

#attach lubridate
> library(lubridate)

# aggregate your object(s) and use lubridate function

> aggregate(test[,-1], list(day(test$date)), mean)
  Group.1 str1 str2 str3
1  10  0.2 0.05 0.15

# or format function

> aggregate(test[,-1], list(format(test$date, "%Y-%m-%d")), mean)
 Group.1 str1 str2 str3
1 1998-01-10  0.2 0.05 0.15

If it does not work with your data you should post at least result of

str(yourdata)

or preferably

dput(yourdata[1:20,])

Cheers
Petr


> -Original Message-
> From: R-help 
> mailto:r-help-boun...@r-project.org>> On Behalf 
> Of Diego Avesani
> Sent: Wednesday, August 1, 2018 8:55 AM
> To: Jeff Newmiller mailto:jdnew...@dcn.davis.ca.us>>
> Cc: r-help mailing list mailto:r-help@r-project.org>>
> Subject: Re: [R] read txt file - date - no space
>
> Dear all,
> I am sorry, I did a lot of confusion. I am sorry, I have to relax and stat 
> all again
> in order to understand.
> If I could I would like to start again, without mixing strategy and waiting 
> for
> your advice.
>
> I am really appreciate you help, really really.
> Here my new file, a *.csv file (buy the way, it is possible to attach it in 
> the
> mailing list?)
>
> date,str1,str2,str3
> 10/1/1998 0:00,0.6,0,0
> 10/1/1998 1:00,0.2,0.2,0.2
> 10/1/1998 2:00,0.6,0.2,0.4
> 10/1/1998 3:00,0,0,0.6
> 10/1/1998 4:00,0,0,0
> 10/1/1998 5:00,0,0,0
> 10/1/1998 6:00,0,0,0
> 10/1/1998 7:00,0.2,0,0
>
>
> I read it as:
> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>
> at this point I would like to have the daily mean.
> What would you suggest?
>
> Really Really thanks,
> You are my lifesaver
>
> Thanks
>
>
>
> Diego
>
>
> On 1 August 2018 at 01:01, Jeff Newmiller 
> mailto:jdnew...@dcn.davis.ca.us>> wrote:
>
> > ... and the most common source of NA values in time data is wrong
> > timezones. You really need to make sure the timezone that is assumed
> > when the character data are converted to

Re: [R] read txt file - date - no space

2018-08-01 Thread Diego Avesani
Dear Pikal, DEar all,

I do not if it could help:
if I print MyData%date, I get (at some point)

[281] "1998-12-10 16:00:00 CET"  "1998-12-10 17:00:00 CET"
"1998-12-10 18:00:00 CET"  "1998-12-10 19:00:00 CET"
 [285] "1998-12-10 20:00:00 CET"  "1998-12-10 21:00:00 CET"
"1998-12-10 22:00:00 CET"  "1998-12-10 23:00:00 CET"
 [289] NA NA NA
 NA
 [293] NA NA NA
 NA
 [297] NA NA NA
 NA


Again Thanks

Diego


On 1 August 2018 at 14:29, Diego Avesani  wrote:

> Dear Pikal, Deal all,
>
> again really thank.
>
> it seems not working.
> Some specifications: My non data are -999, but I could change it.
>
> My final results is:
>
> 11  -55.86242 -55.84764660 -277.4775
> 22  -55.47554 -94.58921682 -277.4845
> 33  -55.47095 -99.20239198 -277.4709
> 44  -55.46470 -55.45952932 -392.9071
> 55  -55.43335 -55.40171682 -388.4110
> 66  -55.40108 -55.37399691 -332.9068
> 77  -55.39201 -55.35156250 -332.8902
> 88 -110.87184   0.16136188 -281.8230
> 99 -110.95077 -55.63856096 -332.9564
> 10  10 -157.64430  -0.06602705 -315.3840
> 11  11 -105.06157   0.11507675 -315.4152
> 12  12  -70.08677 -52.54501096 -316.7247
>
>
> So it is not correct.
> For example for the first day in my csv I would have expected 0.167.
>
> I am going to post what you have suggested:
>
> for  str(MyData)
>
> 'data.frame': 160008 obs. of  4 variables:
>  $ date: POSIXct, format: "1998-01-10 00:00:00" "1998-01-10 01:00:00"
> "1998-01-10 02:00:00" "1998-01-10 03:00:00" ...
>  $ str1: num  0.6 0.2 0.6 0 0 0 0 0.2 0.6 0.2 ...
>  $ str2: num  0 0.2 0.2 0 0 0 0 0 0.2 0.4 ...
>  $ str3: num  0 0.2 0.4 0.6 0 0 0 0 0 0.4 ...
>
> unfortunately, I am not able to post
>
> dput(str[1:20,])
>
> it gives me
>
> Error in str[1:20, ] : object of type 'closure' is not subsettable
>
>
> Thanks again,
> I hope that what I posted could be enough in order to help me.
>
>
>
> Diego
>
>
> On 1 August 2018 at 13:58, PIKAL Petr  wrote:
>
>> Hi
>>
>> I did not get through all answers you already got and you probably
>> obtained similar advice as mine.
>>
>> # read data (if you have csv file just use read.csv)
>> > test<-read.table("clipboard", header=T, sep=",")
>>
>> # control your object(s)
>> > str(test)
>> 'data.frame':   8 obs. of  4 variables:
>>  $ date: Factor w/ 8 levels "10/1/1998 0:00",..: 1 2 3 4 5 6 7 8
>>  $ str1: num  0.6 0.2 0.6 0 0 0 0 0.2
>>  $ str2: num  0 0.2 0.2 0 0 0 0 0
>>  $ str3: num  0 0.2 0.4 0.6 0 0 0 0
>>
>> #if it is OK change first column to real date by POSIXct
>> test$date<-as.POSIXct(test$date, format="%d/%m/%Y %H:%M")
>>
>> #attach lubridate
>> > library(lubridate)
>>
>> # aggregate your object(s) and use lubridate function
>>
>> > aggregate(test[,-1], list(day(test$date)), mean)
>>   Group.1 str1 str2 str3
>> 1  10  0.2 0.05 0.15
>>
>> # or format function
>>
>> > aggregate(test[,-1], list(format(test$date, "%Y-%m-%d")), mean)
>>  Group.1 str1 str2 str3
>> 1 1998-01-10  0.2 0.05 0.15
>>
>> If it does not work with your data you should post at least result of
>>
>> str(yourdata)
>>
>> or preferably
>>
>> dput(yourdata[1:20,])
>>
>> Cheers
>> Petr
>>
>>
>> > -Original Message-
>> > From: R-help  On Behalf Of Diego Avesani
>> > Sent: Wednesday, August 1, 2018 8:55 AM
>> > To: Jeff Newmiller 
>> > Cc: r-help mailing list 
>> > Subject: Re: [R] read txt file - date - no space
>> >
>> > Dear all,
>> > I am sorry, I did a lot of confusion. I am sorry, I have to relax and
>> stat all again
>> > in order to understand.
>> > If I could I would like to start again, without mixing strategy and
>> waiting for
>> > your advice.
>> >
>> > I am really appreciate you help, really really.
>> > Here my new file, a *.csv file (buy the way, it is possible to attach
>> it in the
>> > mailing list?)
>> >
>> > date,str1,str2,str3
>> > 10/1/1998 0:00,0.6,0,0
>> > 10/1/1998 1:00,0.2,0.2,0.2
>> > 10/1/1998 2:00,0.

Re: [R] read txt file - date - no space

2018-08-01 Thread Diego Avesani
Dear Pikal, Deal all,

again really thank.

it seems not working.
Some specifications: My non data are -999, but I could change it.

My final results is:

11  -55.86242 -55.84764660 -277.4775
22  -55.47554 -94.58921682 -277.4845
33  -55.47095 -99.20239198 -277.4709
44  -55.46470 -55.45952932 -392.9071
55  -55.43335 -55.40171682 -388.4110
66  -55.40108 -55.37399691 -332.9068
77  -55.39201 -55.35156250 -332.8902
88 -110.87184   0.16136188 -281.8230
99 -110.95077 -55.63856096 -332.9564
10  10 -157.64430  -0.06602705 -315.3840
11  11 -105.06157   0.11507675 -315.4152
12  12  -70.08677 -52.54501096 -316.7247


So it is not correct.
For example for the first day in my csv I would have expected 0.167.

I am going to post what you have suggested:

for  str(MyData)

'data.frame': 160008 obs. of  4 variables:
 $ date: POSIXct, format: "1998-01-10 00:00:00" "1998-01-10 01:00:00"
"1998-01-10 02:00:00" "1998-01-10 03:00:00" ...
 $ str1: num  0.6 0.2 0.6 0 0 0 0 0.2 0.6 0.2 ...
 $ str2: num  0 0.2 0.2 0 0 0 0 0 0.2 0.4 ...
 $ str3: num  0 0.2 0.4 0.6 0 0 0 0 0 0.4 ...

unfortunately, I am not able to post

dput(str[1:20,])

it gives me

Error in str[1:20, ] : object of type 'closure' is not subsettable


Thanks again,
I hope that what I posted could be enough in order to help me.



Diego


On 1 August 2018 at 13:58, PIKAL Petr  wrote:

> Hi
>
> I did not get through all answers you already got and you probably
> obtained similar advice as mine.
>
> # read data (if you have csv file just use read.csv)
> > test<-read.table("clipboard", header=T, sep=",")
>
> # control your object(s)
> > str(test)
> 'data.frame':   8 obs. of  4 variables:
>  $ date: Factor w/ 8 levels "10/1/1998 0:00",..: 1 2 3 4 5 6 7 8
>  $ str1: num  0.6 0.2 0.6 0 0 0 0 0.2
>  $ str2: num  0 0.2 0.2 0 0 0 0 0
>  $ str3: num  0 0.2 0.4 0.6 0 0 0 0
>
> #if it is OK change first column to real date by POSIXct
> test$date<-as.POSIXct(test$date, format="%d/%m/%Y %H:%M")
>
> #attach lubridate
> > library(lubridate)
>
> # aggregate your object(s) and use lubridate function
>
> > aggregate(test[,-1], list(day(test$date)), mean)
>   Group.1 str1 str2 str3
> 1  10  0.2 0.05 0.15
>
> # or format function
>
> > aggregate(test[,-1], list(format(test$date, "%Y-%m-%d")), mean)
>  Group.1 str1 str2 str3
> 1 1998-01-10  0.2 0.05 0.15
>
> If it does not work with your data you should post at least result of
>
> str(yourdata)
>
> or preferably
>
> dput(yourdata[1:20,])
>
> Cheers
> Petr
>
>
> > -Original Message-
> > From: R-help  On Behalf Of Diego Avesani
> > Sent: Wednesday, August 1, 2018 8:55 AM
> > To: Jeff Newmiller 
> > Cc: r-help mailing list 
> > Subject: Re: [R] read txt file - date - no space
> >
> > Dear all,
> > I am sorry, I did a lot of confusion. I am sorry, I have to relax and
> stat all again
> > in order to understand.
> > If I could I would like to start again, without mixing strategy and
> waiting for
> > your advice.
> >
> > I am really appreciate you help, really really.
> > Here my new file, a *.csv file (buy the way, it is possible to attach it
> in the
> > mailing list?)
> >
> > date,str1,str2,str3
> > 10/1/1998 0:00,0.6,0,0
> > 10/1/1998 1:00,0.2,0.2,0.2
> > 10/1/1998 2:00,0.6,0.2,0.4
> > 10/1/1998 3:00,0,0,0.6
> > 10/1/1998 4:00,0,0,0
> > 10/1/1998 5:00,0,0,0
> > 10/1/1998 6:00,0,0,0
> > 10/1/1998 7:00,0.2,0,0
> >
> >
> > I read it as:
> > MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
> >
> > at this point I would like to have the daily mean.
> > What would you suggest?
> >
> > Really Really thanks,
> > You are my lifesaver
> >
> > Thanks
> >
> >
> >
> > Diego
> >
> >
> > On 1 August 2018 at 01:01, Jeff Newmiller 
> wrote:
> >
> > > ... and the most common source of NA values in time data is wrong
> > > timezones. You really need to make sure the timezone that is assumed
> > > when the character data are converted to POSIXt agrees with the data.
> > > In most cases the easiest way to insure this is to use
> > >
> > > Sys.setenv(TZ="US/Pacific")
> > >
> > > or whatever timezone from
> > >
> > > OlsonNames()
> > >
> > > corresponds with your data. Execute this setenv function before the
> > > strptime or as.POSIXct() fun

Re: [R] read txt file - date - no space

2018-08-01 Thread PIKAL Petr
Hi

I did not get through all answers you already got and you probably obtained 
similar advice as mine.

# read data (if you have csv file just use read.csv)
> test<-read.table("clipboard", header=T, sep=",")

# control your object(s)
> str(test)
'data.frame':   8 obs. of  4 variables:
 $ date: Factor w/ 8 levels "10/1/1998 0:00",..: 1 2 3 4 5 6 7 8
 $ str1: num  0.6 0.2 0.6 0 0 0 0 0.2
 $ str2: num  0 0.2 0.2 0 0 0 0 0
 $ str3: num  0 0.2 0.4 0.6 0 0 0 0

#if it is OK change first column to real date by POSIXct
test$date<-as.POSIXct(test$date, format="%d/%m/%Y %H:%M")

#attach lubridate
> library(lubridate)

# aggregate your object(s) and use lubridate function

> aggregate(test[,-1], list(day(test$date)), mean)
  Group.1 str1 str2 str3
1  10  0.2 0.05 0.15

# or format function

> aggregate(test[,-1], list(format(test$date, "%Y-%m-%d")), mean)
 Group.1 str1 str2 str3
1 1998-01-10  0.2 0.05 0.15

If it does not work with your data you should post at least result of

str(yourdata)

or preferably

dput(yourdata[1:20,])

Cheers
Petr


> -Original Message-
> From: R-help  On Behalf Of Diego Avesani
> Sent: Wednesday, August 1, 2018 8:55 AM
> To: Jeff Newmiller 
> Cc: r-help mailing list 
> Subject: Re: [R] read txt file - date - no space
>
> Dear all,
> I am sorry, I did a lot of confusion. I am sorry, I have to relax and stat 
> all again
> in order to understand.
> If I could I would like to start again, without mixing strategy and waiting 
> for
> your advice.
>
> I am really appreciate you help, really really.
> Here my new file, a *.csv file (buy the way, it is possible to attach it in 
> the
> mailing list?)
>
> date,str1,str2,str3
> 10/1/1998 0:00,0.6,0,0
> 10/1/1998 1:00,0.2,0.2,0.2
> 10/1/1998 2:00,0.6,0.2,0.4
> 10/1/1998 3:00,0,0,0.6
> 10/1/1998 4:00,0,0,0
> 10/1/1998 5:00,0,0,0
> 10/1/1998 6:00,0,0,0
> 10/1/1998 7:00,0.2,0,0
>
>
> I read it as:
> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>
> at this point I would like to have the daily mean.
> What would you suggest?
>
> Really Really thanks,
> You are my lifesaver
>
> Thanks
>
>
>
> Diego
>
>
> On 1 August 2018 at 01:01, Jeff Newmiller  wrote:
>
> > ... and the most common source of NA values in time data is wrong
> > timezones. You really need to make sure the timezone that is assumed
> > when the character data are converted to POSIXt agrees with the data.
> > In most cases the easiest way to insure this is to use
> >
> > Sys.setenv(TZ="US/Pacific")
> >
> > or whatever timezone from
> >
> > OlsonNames()
> >
> > corresponds with your data. Execute this setenv function before the
> > strptime or as.POSIXct() function call.
> >
> > You can use
> >
> > MyData[ is.na(MyData$datetime), ]
> >
> > to see which records are failing to convert time.
> >
> > [1] https://github.com/jdnewmil/eci298sp2016/blob/master/QuickHowto1
> >
> > On July 31, 2018 3:04:05 PM PDT, Jim Lemon 
> wrote:
> > >Hi Diego,
> > >I think the error is due to NA values in your data file. If I extend
> > >your example and run it, I get no errors:
> > >
> > >MyData<-read.table(text="103001930 103001580 103001530
> > >1998-10-01 00:00:00 0.6 0 0
> > >1998-10-01 01:00:00 0.2 0.2 0.2
> > >1998-10-01 02:00:00 0.6 0.2 0.4
> > >1998-10-01 03:00:00 0 0 0.6
> > >1998-10-01 04:00:00 0 0 0
> > >1998-10-01 05:00:00 0 0 0
> > >1998-10-01 06:00:00 0 0 0
> > >1998-10-01 07:00:00 0.2 0 0
> > >1998-10-01 08:00:00 0.6 0 0
> > >1998-10-01 09:00:00 0.2 0.2 0.2
> > >1998-10-01 10:00:00 0.6 0.2 0.4
> > >1998-10-01 11:00:00 0 0 0.6
> > >1998-10-01 12:00:00 0 0 0
> > >1998-10-01 13:00:00 0 0 0
> > >1998-10-01 14:00:00 0 0 0
> > >1998-10-01 15:00:00 0.2 0 0
> > >1998-10-01 16:00:00 0.6 0 0
> > >1998-10-01 17:00:00 0.2 0.2 0.2
> > >1998-10-01 18:00:00 0.6 0.2 0.4
> > >1998-10-01 19:00:00 0 0 0.6
> > >1998-10-01 20:00:00 0 0 0
> > >1998-10-01 21:00:00 0 0 0
> > >1998-10-01 22:00:00 0 0 0
> > >1998-10-01 23:00:00 0.2 0 0
> > >1998-10-02 00:00:00 0.6 0 0
> > >1998-10-02 01:00:00 0.2 0.2 0.2
> > >1998-10-02 02:00:00 0.6 0.2 0.4
> > >1998-10-02 03:00:00 0 0 0.6
> > >1998-10-02 04:00:00 0 0 0
> > >1998-10-02 05:00:00 0 0 0
> > >1998-10-02 06:00:00 0 0 0
> > >1998-10-02 07:00:00 0.2 0 0
> > >1998-10-02 08:00:00 0.6 0 0
> > >1998-10-02

Re: [R] read txt file - date - no space

2018-07-31 Thread Diego Avesani
Dear all,
I am sorry, I did a lot of confusion. I am sorry, I have to relax and stat
all again in order to understand.
If I could I would like to start again, without mixing strategy and waiting
for your advice.

I am really appreciate you help, really really.
Here my new file, a *.csv file (buy the way, it is possible to attach it in
the mailing list?)

date,str1,str2,str3
10/1/1998 0:00,0.6,0,0
10/1/1998 1:00,0.2,0.2,0.2
10/1/1998 2:00,0.6,0.2,0.4
10/1/1998 3:00,0,0,0.6
10/1/1998 4:00,0,0,0
10/1/1998 5:00,0,0,0
10/1/1998 6:00,0,0,0
10/1/1998 7:00,0.2,0,0


I read it as:
MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")

at this point I would like to have the daily mean.
What would you suggest?

Really Really thanks,
You are my lifesaver

Thanks



Diego


On 1 August 2018 at 01:01, Jeff Newmiller  wrote:

> ... and the most common source of NA values in time data is wrong
> timezones. You really need to make sure the timezone that is assumed when
> the character data are converted to POSIXt agrees with the data. In most
> cases the easiest way to insure this is to use
>
> Sys.setenv(TZ="US/Pacific")
>
> or whatever timezone from
>
> OlsonNames()
>
> corresponds with your data. Execute this setenv function before the
> strptime or as.POSIXct() function call.
>
> You can use
>
> MyData[ is.na(MyData$datetime), ]
>
> to see which records are failing to convert time.
>
> [1] https://github.com/jdnewmil/eci298sp2016/blob/master/QuickHowto1
>
> On July 31, 2018 3:04:05 PM PDT, Jim Lemon  wrote:
> >Hi Diego,
> >I think the error is due to NA values in your data file. If I extend
> >your example and run it, I get no errors:
> >
> >MyData<-read.table(text="103001930 103001580 103001530
> >1998-10-01 00:00:00 0.6 0 0
> >1998-10-01 01:00:00 0.2 0.2 0.2
> >1998-10-01 02:00:00 0.6 0.2 0.4
> >1998-10-01 03:00:00 0 0 0.6
> >1998-10-01 04:00:00 0 0 0
> >1998-10-01 05:00:00 0 0 0
> >1998-10-01 06:00:00 0 0 0
> >1998-10-01 07:00:00 0.2 0 0
> >1998-10-01 08:00:00 0.6 0 0
> >1998-10-01 09:00:00 0.2 0.2 0.2
> >1998-10-01 10:00:00 0.6 0.2 0.4
> >1998-10-01 11:00:00 0 0 0.6
> >1998-10-01 12:00:00 0 0 0
> >1998-10-01 13:00:00 0 0 0
> >1998-10-01 14:00:00 0 0 0
> >1998-10-01 15:00:00 0.2 0 0
> >1998-10-01 16:00:00 0.6 0 0
> >1998-10-01 17:00:00 0.2 0.2 0.2
> >1998-10-01 18:00:00 0.6 0.2 0.4
> >1998-10-01 19:00:00 0 0 0.6
> >1998-10-01 20:00:00 0 0 0
> >1998-10-01 21:00:00 0 0 0
> >1998-10-01 22:00:00 0 0 0
> >1998-10-01 23:00:00 0.2 0 0
> >1998-10-02 00:00:00 0.6 0 0
> >1998-10-02 01:00:00 0.2 0.2 0.2
> >1998-10-02 02:00:00 0.6 0.2 0.4
> >1998-10-02 03:00:00 0 0 0.6
> >1998-10-02 04:00:00 0 0 0
> >1998-10-02 05:00:00 0 0 0
> >1998-10-02 06:00:00 0 0 0
> >1998-10-02 07:00:00 0.2 0 0
> >1998-10-02 08:00:00 0.6 0 0
> >1998-10-02 09:00:00 0.2 0.2 0.2
> >1998-10-02 10:00:00 0.6 0.2 0.4
> >1998-10-02 11:00:00 0 0 0.6
> >1998-10-02 12:00:00 0 0 0
> >1998-10-02 13:00:00 0 0 0
> >1998-10-02 14:00:00 0 0 0
> >1998-10-02 15:00:00 0.2 0 0
> >1998-10-02 16:00:00 0.6 0 0
> >1998-10-02 17:00:00 0.2 0.2 0.2
> >1998-10-02 18:00:00 0.6 0.2 0.4
> >1998-10-02 19:00:00 0 0 0.6
> >1998-10-02 20:00:00 0 0 0
> >1998-10-02 21:00:00 0 0 0
> >1998-10-02 22:00:00 0 0 0
> >1998-10-02 23:00:00 0.2 0 0",
> >skip=1,stringsAsFactors=FALSE)
> >names(MyData)<-c("date","time","st1","st2","st3")
> >MyData$datetime<-strptime(paste(MyData$date,MyData$time),
> > format="%Y-%m-%d %H:%M:%S")
> >MyData$datetime
> >st1_daily<-by(MyData$st1,MyData$date,mean)
> >st2_daily<-by(MyData$st2,MyData$date,mean)
> >st3_daily<-by(MyData$st3,MyData$date,mean)
> >st1_daily
> >st2_daily
> >st3_daily
> >
> >Try adding na.rm=TRUE to the "by" calls:
> >
> >st1_daily<-by(MyData$st1,MyData$date,mean,na.rm=TRUE)
> >st2_daily<-by(MyData$st2,MyData$date,mean,na.rm=TRUE)
> >st3_daily<-by(MyData$st3,MyData$date,mean,na.rm=TRUE)
> >
> >Jim
> >
> >On Tue, Jul 31, 2018 at 11:11 PM, Diego Avesani
> > wrote:
> >> Dear all,
> >>
> >> I have still problem with date.
> >> Could you please tel me how to use POSIXct.
> >> Indeed I have found this command:
> >> timeAverage, but I am not able to convert MyDate to properly date.
> >>
> >> Thank a lot
> >> I hope to no bother you, at least too much
> >>
> >>
> >> Diego
> >>
> >>
> >> On 31 July 2018 at 11:12, Diego Avesani 
> >wrote:
> >>>
> >>> Dear Jim, Dear all,
> >>>
> >>> thanks a lot.
> >>>
> >>> Unfortunately, I get the following error:
> >>>
> >>>
> >>>  st1_daily<-by(MyData$st1,MyData$date,mean)
> >>> Error in tapply(seq_len(0L), list(`MyData$date` = c(913L, 914L,
> >925L,  :
> >>>   arguments must have same length
> >>>
> >>>
> >>> This is particularly strange. indeed, if I apply
> >>>
> >>>
> >>> mean(MyData$str1,na.rm=TRUE)
> >>>
> >>>
> >>> it works
> >>>
> >>>
> >>> Sorry, I have to learn a lot.
> >>> You are really boosting me
> >>>
> >>> Diego
> >>>
> >>>
> >>> On 31 July 2018 at 11:02, Jim Lemon  wrote:
> 
>  Hi Diego,
>  One way you can get daily means is:
> 
>  st1_daily<-by(MyData$st1,MyData$date,mean)
> 

Re: [R] read txt file - date - no space

2018-07-31 Thread Jeff Newmiller
... and the most common source of NA values in time data is wrong timezones. 
You really need to make sure the timezone that is assumed when the character 
data are converted to POSIXt agrees with the data. In most cases the easiest 
way to insure this is to use

Sys.setenv(TZ="US/Pacific")

or whatever timezone from

OlsonNames()

corresponds with your data. Execute this setenv function before the strptime or 
as.POSIXct() function call.

You can use 

MyData[ is.na(MyData$datetime), ]

to see which records are failing to convert time.

[1] https://github.com/jdnewmil/eci298sp2016/blob/master/QuickHowto1

On July 31, 2018 3:04:05 PM PDT, Jim Lemon  wrote:
>Hi Diego,
>I think the error is due to NA values in your data file. If I extend
>your example and run it, I get no errors:
>
>MyData<-read.table(text="103001930 103001580 103001530
>1998-10-01 00:00:00 0.6 0 0
>1998-10-01 01:00:00 0.2 0.2 0.2
>1998-10-01 02:00:00 0.6 0.2 0.4
>1998-10-01 03:00:00 0 0 0.6
>1998-10-01 04:00:00 0 0 0
>1998-10-01 05:00:00 0 0 0
>1998-10-01 06:00:00 0 0 0
>1998-10-01 07:00:00 0.2 0 0
>1998-10-01 08:00:00 0.6 0 0
>1998-10-01 09:00:00 0.2 0.2 0.2
>1998-10-01 10:00:00 0.6 0.2 0.4
>1998-10-01 11:00:00 0 0 0.6
>1998-10-01 12:00:00 0 0 0
>1998-10-01 13:00:00 0 0 0
>1998-10-01 14:00:00 0 0 0
>1998-10-01 15:00:00 0.2 0 0
>1998-10-01 16:00:00 0.6 0 0
>1998-10-01 17:00:00 0.2 0.2 0.2
>1998-10-01 18:00:00 0.6 0.2 0.4
>1998-10-01 19:00:00 0 0 0.6
>1998-10-01 20:00:00 0 0 0
>1998-10-01 21:00:00 0 0 0
>1998-10-01 22:00:00 0 0 0
>1998-10-01 23:00:00 0.2 0 0
>1998-10-02 00:00:00 0.6 0 0
>1998-10-02 01:00:00 0.2 0.2 0.2
>1998-10-02 02:00:00 0.6 0.2 0.4
>1998-10-02 03:00:00 0 0 0.6
>1998-10-02 04:00:00 0 0 0
>1998-10-02 05:00:00 0 0 0
>1998-10-02 06:00:00 0 0 0
>1998-10-02 07:00:00 0.2 0 0
>1998-10-02 08:00:00 0.6 0 0
>1998-10-02 09:00:00 0.2 0.2 0.2
>1998-10-02 10:00:00 0.6 0.2 0.4
>1998-10-02 11:00:00 0 0 0.6
>1998-10-02 12:00:00 0 0 0
>1998-10-02 13:00:00 0 0 0
>1998-10-02 14:00:00 0 0 0
>1998-10-02 15:00:00 0.2 0 0
>1998-10-02 16:00:00 0.6 0 0
>1998-10-02 17:00:00 0.2 0.2 0.2
>1998-10-02 18:00:00 0.6 0.2 0.4
>1998-10-02 19:00:00 0 0 0.6
>1998-10-02 20:00:00 0 0 0
>1998-10-02 21:00:00 0 0 0
>1998-10-02 22:00:00 0 0 0
>1998-10-02 23:00:00 0.2 0 0",
>skip=1,stringsAsFactors=FALSE)
>names(MyData)<-c("date","time","st1","st2","st3")
>MyData$datetime<-strptime(paste(MyData$date,MyData$time),
> format="%Y-%m-%d %H:%M:%S")
>MyData$datetime
>st1_daily<-by(MyData$st1,MyData$date,mean)
>st2_daily<-by(MyData$st2,MyData$date,mean)
>st3_daily<-by(MyData$st3,MyData$date,mean)
>st1_daily
>st2_daily
>st3_daily
>
>Try adding na.rm=TRUE to the "by" calls:
>
>st1_daily<-by(MyData$st1,MyData$date,mean,na.rm=TRUE)
>st2_daily<-by(MyData$st2,MyData$date,mean,na.rm=TRUE)
>st3_daily<-by(MyData$st3,MyData$date,mean,na.rm=TRUE)
>
>Jim
>
>On Tue, Jul 31, 2018 at 11:11 PM, Diego Avesani
> wrote:
>> Dear all,
>>
>> I have still problem with date.
>> Could you please tel me how to use POSIXct.
>> Indeed I have found this command:
>> timeAverage, but I am not able to convert MyDate to properly date.
>>
>> Thank a lot
>> I hope to no bother you, at least too much
>>
>>
>> Diego
>>
>>
>> On 31 July 2018 at 11:12, Diego Avesani 
>wrote:
>>>
>>> Dear Jim, Dear all,
>>>
>>> thanks a lot.
>>>
>>> Unfortunately, I get the following error:
>>>
>>>
>>>  st1_daily<-by(MyData$st1,MyData$date,mean)
>>> Error in tapply(seq_len(0L), list(`MyData$date` = c(913L, 914L,
>925L,  :
>>>   arguments must have same length
>>>
>>>
>>> This is particularly strange. indeed, if I apply
>>>
>>>
>>> mean(MyData$str1,na.rm=TRUE)
>>>
>>>
>>> it works
>>>
>>>
>>> Sorry, I have to learn a lot.
>>> You are really boosting me
>>>
>>> Diego
>>>
>>>
>>> On 31 July 2018 at 11:02, Jim Lemon  wrote:

 Hi Diego,
 One way you can get daily means is:

 st1_daily<-by(MyData$st1,MyData$date,mean)
 st2_daily<-by(MyData$st2,MyData$date,mean)
 st3_daily<-by(MyData$st3,MyData$date,mean)

 Jim

 On Tue, Jul 31, 2018 at 6:51 PM, Diego Avesani
>
 wrote:
 > Dear all,
 > I have found the error, my fault. Sorry.
 > There was an extra come in the headers line.
 > Thanks again.
 >
 > If I can I would like to ask you another questions about the
>imported
 > data.
 > I would like to compute the daily average of the different date.
 > Basically I
 > have hourly data, I would like to ave the daily mean of them.
 >
 > Is there some special commands?
 >
 > Thanks a lot.
 >
 >
 > Diego
 >
 >
 > On 31 July 2018 at 10:40, Diego Avesani 
 > wrote:
 >>
 >> Dear all,
 >> I move to csv file because originally the date where in csv
>file.
 >> In addition, due to the fact that, as you told me, read.csv is a
 >> special
 >> case of read.table, I prefer start to learn from the simplest
>one.
 >> After that, I will try also the *.txt format.
 >>
 >> with read.csv, something stran

Re: [R] read txt file - date - no space

2018-07-31 Thread Jim Lemon
Hi Diego,
I think the error is due to NA values in your data file. If I extend
your example and run it, I get no errors:

MyData<-read.table(text="103001930 103001580 103001530
1998-10-01 00:00:00 0.6 0 0
1998-10-01 01:00:00 0.2 0.2 0.2
1998-10-01 02:00:00 0.6 0.2 0.4
1998-10-01 03:00:00 0 0 0.6
1998-10-01 04:00:00 0 0 0
1998-10-01 05:00:00 0 0 0
1998-10-01 06:00:00 0 0 0
1998-10-01 07:00:00 0.2 0 0
1998-10-01 08:00:00 0.6 0 0
1998-10-01 09:00:00 0.2 0.2 0.2
1998-10-01 10:00:00 0.6 0.2 0.4
1998-10-01 11:00:00 0 0 0.6
1998-10-01 12:00:00 0 0 0
1998-10-01 13:00:00 0 0 0
1998-10-01 14:00:00 0 0 0
1998-10-01 15:00:00 0.2 0 0
1998-10-01 16:00:00 0.6 0 0
1998-10-01 17:00:00 0.2 0.2 0.2
1998-10-01 18:00:00 0.6 0.2 0.4
1998-10-01 19:00:00 0 0 0.6
1998-10-01 20:00:00 0 0 0
1998-10-01 21:00:00 0 0 0
1998-10-01 22:00:00 0 0 0
1998-10-01 23:00:00 0.2 0 0
1998-10-02 00:00:00 0.6 0 0
1998-10-02 01:00:00 0.2 0.2 0.2
1998-10-02 02:00:00 0.6 0.2 0.4
1998-10-02 03:00:00 0 0 0.6
1998-10-02 04:00:00 0 0 0
1998-10-02 05:00:00 0 0 0
1998-10-02 06:00:00 0 0 0
1998-10-02 07:00:00 0.2 0 0
1998-10-02 08:00:00 0.6 0 0
1998-10-02 09:00:00 0.2 0.2 0.2
1998-10-02 10:00:00 0.6 0.2 0.4
1998-10-02 11:00:00 0 0 0.6
1998-10-02 12:00:00 0 0 0
1998-10-02 13:00:00 0 0 0
1998-10-02 14:00:00 0 0 0
1998-10-02 15:00:00 0.2 0 0
1998-10-02 16:00:00 0.6 0 0
1998-10-02 17:00:00 0.2 0.2 0.2
1998-10-02 18:00:00 0.6 0.2 0.4
1998-10-02 19:00:00 0 0 0.6
1998-10-02 20:00:00 0 0 0
1998-10-02 21:00:00 0 0 0
1998-10-02 22:00:00 0 0 0
1998-10-02 23:00:00 0.2 0 0",
skip=1,stringsAsFactors=FALSE)
names(MyData)<-c("date","time","st1","st2","st3")
MyData$datetime<-strptime(paste(MyData$date,MyData$time),
 format="%Y-%m-%d %H:%M:%S")
MyData$datetime
st1_daily<-by(MyData$st1,MyData$date,mean)
st2_daily<-by(MyData$st2,MyData$date,mean)
st3_daily<-by(MyData$st3,MyData$date,mean)
st1_daily
st2_daily
st3_daily

Try adding na.rm=TRUE to the "by" calls:

st1_daily<-by(MyData$st1,MyData$date,mean,na.rm=TRUE)
st2_daily<-by(MyData$st2,MyData$date,mean,na.rm=TRUE)
st3_daily<-by(MyData$st3,MyData$date,mean,na.rm=TRUE)

Jim

On Tue, Jul 31, 2018 at 11:11 PM, Diego Avesani  wrote:
> Dear all,
>
> I have still problem with date.
> Could you please tel me how to use POSIXct.
> Indeed I have found this command:
> timeAverage, but I am not able to convert MyDate to properly date.
>
> Thank a lot
> I hope to no bother you, at least too much
>
>
> Diego
>
>
> On 31 July 2018 at 11:12, Diego Avesani  wrote:
>>
>> Dear Jim, Dear all,
>>
>> thanks a lot.
>>
>> Unfortunately, I get the following error:
>>
>>
>>  st1_daily<-by(MyData$st1,MyData$date,mean)
>> Error in tapply(seq_len(0L), list(`MyData$date` = c(913L, 914L, 925L,  :
>>   arguments must have same length
>>
>>
>> This is particularly strange. indeed, if I apply
>>
>>
>> mean(MyData$str1,na.rm=TRUE)
>>
>>
>> it works
>>
>>
>> Sorry, I have to learn a lot.
>> You are really boosting me
>>
>> Diego
>>
>>
>> On 31 July 2018 at 11:02, Jim Lemon  wrote:
>>>
>>> Hi Diego,
>>> One way you can get daily means is:
>>>
>>> st1_daily<-by(MyData$st1,MyData$date,mean)
>>> st2_daily<-by(MyData$st2,MyData$date,mean)
>>> st3_daily<-by(MyData$st3,MyData$date,mean)
>>>
>>> Jim
>>>
>>> On Tue, Jul 31, 2018 at 6:51 PM, Diego Avesani 
>>> wrote:
>>> > Dear all,
>>> > I have found the error, my fault. Sorry.
>>> > There was an extra come in the headers line.
>>> > Thanks again.
>>> >
>>> > If I can I would like to ask you another questions about the imported
>>> > data.
>>> > I would like to compute the daily average of the different date.
>>> > Basically I
>>> > have hourly data, I would like to ave the daily mean of them.
>>> >
>>> > Is there some special commands?
>>> >
>>> > Thanks a lot.
>>> >
>>> >
>>> > Diego
>>> >
>>> >
>>> > On 31 July 2018 at 10:40, Diego Avesani 
>>> > wrote:
>>> >>
>>> >> Dear all,
>>> >> I move to csv file because originally the date where in csv file.
>>> >> In addition, due to the fact that, as you told me, read.csv is a
>>> >> special
>>> >> case of read.table, I prefer start to learn from the simplest one.
>>> >> After that, I will try also the *.txt format.
>>> >>
>>> >> with read.csv, something strange happened:
>>> >>
>>> >> This us now the file:
>>> >>
>>> >> date,st1,st2,st3,
>>> >> 10/1/1998 0:00,0.6,0,0
>>> >> 10/1/1998 1:00,0.2,0.2,0.2
>>> >> 10/1/1998 2:00,0.6,0.2,0.4
>>> >> 10/1/1998 3:00,0,0,0.6
>>> >> 10/1/1998 4:00,0,0,0
>>> >> 10/1/1998 5:00,0,0,0
>>> >> 10/1/1998 6:00,0,0,0
>>> >> 10/1/1998 7:00,0.2,0,0
>>> >> 10/1/1998 8:00,0.6,0.2,0
>>> >> 10/1/1998 9:00,0.2,0.4,0.4
>>> >> 10/1/1998 10:00,0,0.4,0.2
>>> >>
>>> >> When I apply:
>>> >> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>>> >>
>>> >> this is the results:
>>> >>
>>> >> 10/1/1998 0:000.60.000.0 NA
>>> >> 210/1/1998 1:000.20.200.2 NA
>>> >> 310/1/1998 2:000.60.200.4 NA
>>> >> 410/1/1998 3:000.00.000.6 NA
>>> >> 510/1/1998 4:000.00.000.0 NA
>

Re: [R] read txt file - date - no space

2018-07-31 Thread Diego Avesani
Dear all,

I have still problem with date.
Could you please tel me how to use POSIXct.
Indeed I have found this command:
timeAverage, but I am not able to convert MyDate to properly date.

Thank a lot
I hope to no bother you, at least too much


Diego


On 31 July 2018 at 11:12, Diego Avesani  wrote:

> Dear Jim, Dear all,
>
> thanks a lot.
>
> Unfortunately, I get the following error:
>
>
>  st1_daily<-by(MyData$st1,MyData$date,mean)Error in tapply(seq_len(0L), 
> list(`MyData$date` = c(913L, 914L, 925L,  :
>   arguments must have same length
>
>
> This is particularly strange. indeed, if I apply
>
>
> mean(MyData$str1,na.rm=TRUE)
>
>
> it works
>
>
> Sorry, I have to learn a lot.
> You are really boosting me
>
> Diego
>
>
> On 31 July 2018 at 11:02, Jim Lemon  wrote:
>
>> Hi Diego,
>> One way you can get daily means is:
>>
>> st1_daily<-by(MyData$st1,MyData$date,mean)
>> st2_daily<-by(MyData$st2,MyData$date,mean)
>> st3_daily<-by(MyData$st3,MyData$date,mean)
>>
>> Jim
>>
>> On Tue, Jul 31, 2018 at 6:51 PM, Diego Avesani 
>> wrote:
>> > Dear all,
>> > I have found the error, my fault. Sorry.
>> > There was an extra come in the headers line.
>> > Thanks again.
>> >
>> > If I can I would like to ask you another questions about the imported
>> data.
>> > I would like to compute the daily average of the different date.
>> Basically I
>> > have hourly data, I would like to ave the daily mean of them.
>> >
>> > Is there some special commands?
>> >
>> > Thanks a lot.
>> >
>> >
>> > Diego
>> >
>> >
>> > On 31 July 2018 at 10:40, Diego Avesani 
>> wrote:
>> >>
>> >> Dear all,
>> >> I move to csv file because originally the date where in csv file.
>> >> In addition, due to the fact that, as you told me, read.csv is a
>> special
>> >> case of read.table, I prefer start to learn from the simplest one.
>> >> After that, I will try also the *.txt format.
>> >>
>> >> with read.csv, something strange happened:
>> >>
>> >> This us now the file:
>> >>
>> >> date,st1,st2,st3,
>> >> 10/1/1998 0:00,0.6,0,0
>> >> 10/1/1998 1:00,0.2,0.2,0.2
>> >> 10/1/1998 2:00,0.6,0.2,0.4
>> >> 10/1/1998 3:00,0,0,0.6
>> >> 10/1/1998 4:00,0,0,0
>> >> 10/1/1998 5:00,0,0,0
>> >> 10/1/1998 6:00,0,0,0
>> >> 10/1/1998 7:00,0.2,0,0
>> >> 10/1/1998 8:00,0.6,0.2,0
>> >> 10/1/1998 9:00,0.2,0.4,0.4
>> >> 10/1/1998 10:00,0,0.4,0.2
>> >>
>> >> When I apply:
>> >> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>> >>
>> >> this is the results:
>> >>
>> >> 10/1/1998 0:000.60.000.0 NA
>> >> 210/1/1998 1:000.20.200.2 NA
>> >> 310/1/1998 2:000.60.200.4 NA
>> >> 410/1/1998 3:000.00.000.6 NA
>> >> 510/1/1998 4:000.00.000.0 NA
>> >> 610/1/1998 5:000.00.000.0 NA
>> >> 710/1/1998 6:000.00.000.0 NA
>> >> 810/1/1998 7:000.20.000.0 NA
>> >>
>> >> I do not understand why.
>> >> Something wrong with date?
>> >>
>> >> really really thanks,
>> >> I appreciate a lot all your helps.
>> >>
>> >> Diedro
>> >>
>> >>
>> >> Diego
>> >>
>> >>
>> >> On 31 July 2018 at 01:25, MacQueen, Don  wrote:
>> >>>
>> >>> Or, without removing the first line
>> >>>   dadf <- read.table("xxx.txt", stringsAsFactors=FALSE, skip=1)
>> >>>
>> >>> Another alternative,
>> >>>dadf$datetime <- as.POSIXct(paste(dadf$V1,dadf$V2))
>> >>> since the dates appear to be in the default format.
>> >>> (I generally prefer to work with datetimes in POSIXct class rather
>> than
>> >>> POSIXlt class)
>> >>>
>> >>> -Don
>> >>>
>> >>> --
>> >>> Don MacQueen
>> >>> Lawrence Livermore National Laboratory
>> >>> 7000 East Ave., L-627
>> >>> Livermore, CA 94550
>> >>> 925-423-1062
>> >>> Lab cell 925-724-7509
>> >>>
>> >>>
>> >>>
>> >>> On 7/30/18, 4:03 PM, "R-help on behalf of Jim Lemon"
>> >>> 
>> wrote:
>> >>>
>> >>> Hi Diego,
>> >>> You may have to do some conversion as you have three fields in the
>> >>> first line using the default space separator and five fields in
>> >>> subsequent lines. If the first line doesn't contain any important
>> >>> data
>> >>> you can just delete it or replace it with a meaningful header line
>> >>> with five fields and save the file under another name.
>> >>>
>> >>> It looks as thought you have date-time as two fields. If so, you
>> can
>> >>> just read the first field if you only want the date:
>> >>>
>> >>> # assume you have removed the first line
>> >>> dadf<-read.table("xxx.txt",stringsAsFactors=FALSE
>> >>> dadf$date<-as.Date(dadf$V1,format="%Y-%m-%d")
>> >>>
>> >>> If you want the date/time:
>> >>>
>> >>> dadf$datetime<-strptime(paste(dadf$V1,dadf$V2),format="%Y-%m-%d
>> >>> %H:%M:%S")
>> >>>
>> >>> Jim
>> >>>
>> >>> On Tue, Jul 31, 2018 at 12:29 AM, Diego Avesani
>> >>>  wrote:
>> >>> > Dear all,
>> >>> >
>> >>> > I am dealing with the reading of a *.txt file.
>> >>> > The txt file the following shape:
>> >>> >
>> >>> > 103001930

Re: [R] read txt file - date - no space

2018-07-31 Thread Diego Avesani
Dear Jim, Dear all,

thanks a lot.

Unfortunately, I get the following error:


 st1_daily<-by(MyData$st1,MyData$date,mean)Error in
tapply(seq_len(0L), list(`MyData$date` = c(913L, 914L, 925L,  :
  arguments must have same length


This is particularly strange. indeed, if I apply


mean(MyData$str1,na.rm=TRUE)


it works


Sorry, I have to learn a lot.
You are really boosting me

Diego


On 31 July 2018 at 11:02, Jim Lemon  wrote:

> Hi Diego,
> One way you can get daily means is:
>
> st1_daily<-by(MyData$st1,MyData$date,mean)
> st2_daily<-by(MyData$st2,MyData$date,mean)
> st3_daily<-by(MyData$st3,MyData$date,mean)
>
> Jim
>
> On Tue, Jul 31, 2018 at 6:51 PM, Diego Avesani 
> wrote:
> > Dear all,
> > I have found the error, my fault. Sorry.
> > There was an extra come in the headers line.
> > Thanks again.
> >
> > If I can I would like to ask you another questions about the imported
> data.
> > I would like to compute the daily average of the different date.
> Basically I
> > have hourly data, I would like to ave the daily mean of them.
> >
> > Is there some special commands?
> >
> > Thanks a lot.
> >
> >
> > Diego
> >
> >
> > On 31 July 2018 at 10:40, Diego Avesani  wrote:
> >>
> >> Dear all,
> >> I move to csv file because originally the date where in csv file.
> >> In addition, due to the fact that, as you told me, read.csv is a special
> >> case of read.table, I prefer start to learn from the simplest one.
> >> After that, I will try also the *.txt format.
> >>
> >> with read.csv, something strange happened:
> >>
> >> This us now the file:
> >>
> >> date,st1,st2,st3,
> >> 10/1/1998 0:00,0.6,0,0
> >> 10/1/1998 1:00,0.2,0.2,0.2
> >> 10/1/1998 2:00,0.6,0.2,0.4
> >> 10/1/1998 3:00,0,0,0.6
> >> 10/1/1998 4:00,0,0,0
> >> 10/1/1998 5:00,0,0,0
> >> 10/1/1998 6:00,0,0,0
> >> 10/1/1998 7:00,0.2,0,0
> >> 10/1/1998 8:00,0.6,0.2,0
> >> 10/1/1998 9:00,0.2,0.4,0.4
> >> 10/1/1998 10:00,0,0.4,0.2
> >>
> >> When I apply:
> >> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
> >>
> >> this is the results:
> >>
> >> 10/1/1998 0:000.60.000.0 NA
> >> 210/1/1998 1:000.20.200.2 NA
> >> 310/1/1998 2:000.60.200.4 NA
> >> 410/1/1998 3:000.00.000.6 NA
> >> 510/1/1998 4:000.00.000.0 NA
> >> 610/1/1998 5:000.00.000.0 NA
> >> 710/1/1998 6:000.00.000.0 NA
> >> 810/1/1998 7:000.20.000.0 NA
> >>
> >> I do not understand why.
> >> Something wrong with date?
> >>
> >> really really thanks,
> >> I appreciate a lot all your helps.
> >>
> >> Diedro
> >>
> >>
> >> Diego
> >>
> >>
> >> On 31 July 2018 at 01:25, MacQueen, Don  wrote:
> >>>
> >>> Or, without removing the first line
> >>>   dadf <- read.table("xxx.txt", stringsAsFactors=FALSE, skip=1)
> >>>
> >>> Another alternative,
> >>>dadf$datetime <- as.POSIXct(paste(dadf$V1,dadf$V2))
> >>> since the dates appear to be in the default format.
> >>> (I generally prefer to work with datetimes in POSIXct class rather than
> >>> POSIXlt class)
> >>>
> >>> -Don
> >>>
> >>> --
> >>> Don MacQueen
> >>> Lawrence Livermore National Laboratory
> >>> 7000 East Ave., L-627
> >>> Livermore, CA 94550
> >>> 925-423-1062
> >>> Lab cell 925-724-7509
> >>>
> >>>
> >>>
> >>> On 7/30/18, 4:03 PM, "R-help on behalf of Jim Lemon"
> >>> 
> wrote:
> >>>
> >>> Hi Diego,
> >>> You may have to do some conversion as you have three fields in the
> >>> first line using the default space separator and five fields in
> >>> subsequent lines. If the first line doesn't contain any important
> >>> data
> >>> you can just delete it or replace it with a meaningful header line
> >>> with five fields and save the file under another name.
> >>>
> >>> It looks as thought you have date-time as two fields. If so, you
> can
> >>> just read the first field if you only want the date:
> >>>
> >>> # assume you have removed the first line
> >>> dadf<-read.table("xxx.txt",stringsAsFactors=FALSE
> >>> dadf$date<-as.Date(dadf$V1,format="%Y-%m-%d")
> >>>
> >>> If you want the date/time:
> >>>
> >>> dadf$datetime<-strptime(paste(dadf$V1,dadf$V2),format="%Y-%m-%d
> >>> %H:%M:%S")
> >>>
> >>> Jim
> >>>
> >>> On Tue, Jul 31, 2018 at 12:29 AM, Diego Avesani
> >>>  wrote:
> >>> > Dear all,
> >>> >
> >>> > I am dealing with the reading of a *.txt file.
> >>> > The txt file the following shape:
> >>> >
> >>> > 103001930 103001580 103001530
> >>> > 1998-10-01 00:00:00 0.6 0 0
> >>> > 1998-10-01 01:00:00 0.2 0.2 0.2
> >>> > 1998-10-01 02:00:00 0.6 0.2 0.4
> >>> > 1998-10-01 03:00:00 0 0 0.6
> >>> > 1998-10-01 04:00:00 0 0 0
> >>> > 1998-10-01 05:00:00 0 0 0
> >>> > 1998-10-01 06:00:00 0 0 0
> >>> > 1998-10-01 07:00:00 0.2 0 0
> >>> >
> >>> > If it is possible I have a coupe of questions, which will sound
> >>> stupid but
> >>> > they are important to me in order 

Re: [R] read txt file - date - no space

2018-07-31 Thread Diego Avesani
Dear all,
I have found the error, my fault. Sorry.
There was an extra come in the headers line.
Thanks again.

If I can I would like to ask you another questions about the imported data.
I would like to compute the daily average of the different date. Basically
I have hourly data, I would like to ave the daily mean of them.

Is there some special commands?

Thanks a lot.


Diego


On 31 July 2018 at 10:40, Diego Avesani  wrote:

> Dear all,
> I move to csv file because originally the date where in csv file.
> In addition, due to the fact that, as you told me, read.csv is a special
> case of read.table, I prefer start to learn from the simplest one.
> After that, I will try also the *.txt format.
>
> with read.csv, something strange happened:
>
> This us now the file:
>
> date,st1,st2,st3,
> 10/1/1998 0:00,0.6,0,0
> 10/1/1998 1:00,0.2,0.2,0.2
> 10/1/1998 2:00,0.6,0.2,0.4
> 10/1/1998 3:00,0,0,0.6
> 10/1/1998 4:00,0,0,0
> 10/1/1998 5:00,0,0,0
> 10/1/1998 6:00,0,0,0
> 10/1/1998 7:00,0.2,0,0
> 10/1/1998 8:00,0.6,0.2,0
> 10/1/1998 9:00,0.2,0.4,0.4
> 10/1/1998 10:00,0,0.4,0.2
>
> When I apply:
> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>
> this is the results:
>
> 10/1/1998 0:000.60.000.0 NA
> 210/1/1998 1:000.20.200.2 NA
> 310/1/1998 2:000.60.200.4 NA
> 410/1/1998 3:000.00.000.6 NA
> 510/1/1998 4:000.00.000.0 NA
> 610/1/1998 5:000.00.000.0 NA
> 710/1/1998 6:000.00.000.0 NA
> 810/1/1998 7:000.20.000.0 NA
>
> I do not understand why.
> Something wrong with date?
>
> really really thanks,
> I appreciate a lot all your helps.
>
> Diedro
>
>
> Diego
>
>
> On 31 July 2018 at 01:25, MacQueen, Don  wrote:
>
>> Or, without removing the first line
>>   dadf <- read.table("xxx.txt", stringsAsFactors=FALSE, skip=1)
>>
>> Another alternative,
>>dadf$datetime <- as.POSIXct(paste(dadf$V1,dadf$V2))
>> since the dates appear to be in the default format.
>> (I generally prefer to work with datetimes in POSIXct class rather than
>> POSIXlt class)
>>
>> -Don
>>
>> --
>> Don MacQueen
>> Lawrence Livermore National Laboratory
>> 7000 East Ave., L-627
>> Livermore, CA 94550
>> 925-423-1062
>> Lab cell 925-724-7509
>>
>>
>>
>> On 7/30/18, 4:03 PM, "R-help on behalf of Jim Lemon" <
>> r-help-boun...@r-project.org on behalf of drjimle...@gmail.com> wrote:
>>
>> Hi Diego,
>> You may have to do some conversion as you have three fields in the
>> first line using the default space separator and five fields in
>> subsequent lines. If the first line doesn't contain any important data
>> you can just delete it or replace it with a meaningful header line
>> with five fields and save the file under another name.
>>
>> It looks as thought you have date-time as two fields. If so, you can
>> just read the first field if you only want the date:
>>
>> # assume you have removed the first line
>> dadf<-read.table("xxx.txt",stringsAsFactors=FALSE
>> dadf$date<-as.Date(dadf$V1,format="%Y-%m-%d")
>>
>> If you want the date/time:
>>
>> dadf$datetime<-strptime(paste(dadf$V1,dadf$V2),format="%Y-%m-%d
>> %H:%M:%S")
>>
>> Jim
>>
>> On Tue, Jul 31, 2018 at 12:29 AM, Diego Avesani <
>> diego.aves...@gmail.com> wrote:
>> > Dear all,
>> >
>> > I am dealing with the reading of a *.txt file.
>> > The txt file the following shape:
>> >
>> > 103001930 103001580 103001530
>> > 1998-10-01 00:00:00 0.6 0 0
>> > 1998-10-01 01:00:00 0.2 0.2 0.2
>> > 1998-10-01 02:00:00 0.6 0.2 0.4
>> > 1998-10-01 03:00:00 0 0 0.6
>> > 1998-10-01 04:00:00 0 0 0
>> > 1998-10-01 05:00:00 0 0 0
>> > 1998-10-01 06:00:00 0 0 0
>> > 1998-10-01 07:00:00 0.2 0 0
>> >
>> > If it is possible I have a coupe of questions, which will sound
>> stupid but
>> > they are important to me in order to understand ho R deal with file
>> or date.
>> >
>> > 1) Do I have to convert it to a *csv file?
>> > 2) Can a deal with space and not ","
>> > 3) How can I read date?
>> >
>> > thanks a lot to all of you,
>> > Thanks
>> >
>> >
>> > Diego
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, repr

Re: [R] read txt file - date - no space

2018-07-31 Thread Diego Avesani
Dear all,
I move to csv file because originally the date where in csv file.
In addition, due to the fact that, as you told me, read.csv is a special
case of read.table, I prefer start to learn from the simplest one.
After that, I will try also the *.txt format.

with read.csv, something strange happened:

This us now the file:

date,st1,st2,st3,
10/1/1998 0:00,0.6,0,0
10/1/1998 1:00,0.2,0.2,0.2
10/1/1998 2:00,0.6,0.2,0.4
10/1/1998 3:00,0,0,0.6
10/1/1998 4:00,0,0,0
10/1/1998 5:00,0,0,0
10/1/1998 6:00,0,0,0
10/1/1998 7:00,0.2,0,0
10/1/1998 8:00,0.6,0.2,0
10/1/1998 9:00,0.2,0.4,0.4
10/1/1998 10:00,0,0.4,0.2

When I apply:
MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")

this is the results:

10/1/1998 0:000.60.000.0 NA
210/1/1998 1:000.20.200.2 NA
310/1/1998 2:000.60.200.4 NA
410/1/1998 3:000.00.000.6 NA
510/1/1998 4:000.00.000.0 NA
610/1/1998 5:000.00.000.0 NA
710/1/1998 6:000.00.000.0 NA
810/1/1998 7:000.20.000.0 NA

I do not understand why.
Something wrong with date?

really really thanks,
I appreciate a lot all your helps.

Diedro


Diego


On 31 July 2018 at 01:25, MacQueen, Don  wrote:

> Or, without removing the first line
>   dadf <- read.table("xxx.txt", stringsAsFactors=FALSE, skip=1)
>
> Another alternative,
>dadf$datetime <- as.POSIXct(paste(dadf$V1,dadf$V2))
> since the dates appear to be in the default format.
> (I generally prefer to work with datetimes in POSIXct class rather than
> POSIXlt class)
>
> -Don
>
> --
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> Lab cell 925-724-7509
>
>
>
> On 7/30/18, 4:03 PM, "R-help on behalf of Jim Lemon" <
> r-help-boun...@r-project.org on behalf of drjimle...@gmail.com> wrote:
>
> Hi Diego,
> You may have to do some conversion as you have three fields in the
> first line using the default space separator and five fields in
> subsequent lines. If the first line doesn't contain any important data
> you can just delete it or replace it with a meaningful header line
> with five fields and save the file under another name.
>
> It looks as thought you have date-time as two fields. If so, you can
> just read the first field if you only want the date:
>
> # assume you have removed the first line
> dadf<-read.table("xxx.txt",stringsAsFactors=FALSE
> dadf$date<-as.Date(dadf$V1,format="%Y-%m-%d")
>
> If you want the date/time:
>
> dadf$datetime<-strptime(paste(dadf$V1,dadf$V2),format="%Y-%m-%d
> %H:%M:%S")
>
> Jim
>
> On Tue, Jul 31, 2018 at 12:29 AM, Diego Avesani <
> diego.aves...@gmail.com> wrote:
> > Dear all,
> >
> > I am dealing with the reading of a *.txt file.
> > The txt file the following shape:
> >
> > 103001930 103001580 103001530
> > 1998-10-01 00:00:00 0.6 0 0
> > 1998-10-01 01:00:00 0.2 0.2 0.2
> > 1998-10-01 02:00:00 0.6 0.2 0.4
> > 1998-10-01 03:00:00 0 0 0.6
> > 1998-10-01 04:00:00 0 0 0
> > 1998-10-01 05:00:00 0 0 0
> > 1998-10-01 06:00:00 0 0 0
> > 1998-10-01 07:00:00 0.2 0 0
> >
> > If it is possible I have a coupe of questions, which will sound
> stupid but
> > they are important to me in order to understand ho R deal with file
> or date.
> >
> > 1) Do I have to convert it to a *csv file?
> > 2) Can a deal with space and not ","
> > 3) How can I read date?
> >
> > thanks a lot to all of you,
> > Thanks
> >
> >
> > Diego
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read txt file - date - no space

2018-07-31 Thread Jim Lemon
Hi Diego,
One way you can get daily means is:

st1_daily<-by(MyData$st1,MyData$date,mean)
st2_daily<-by(MyData$st2,MyData$date,mean)
st3_daily<-by(MyData$st3,MyData$date,mean)

Jim

On Tue, Jul 31, 2018 at 6:51 PM, Diego Avesani  wrote:
> Dear all,
> I have found the error, my fault. Sorry.
> There was an extra come in the headers line.
> Thanks again.
>
> If I can I would like to ask you another questions about the imported data.
> I would like to compute the daily average of the different date. Basically I
> have hourly data, I would like to ave the daily mean of them.
>
> Is there some special commands?
>
> Thanks a lot.
>
>
> Diego
>
>
> On 31 July 2018 at 10:40, Diego Avesani  wrote:
>>
>> Dear all,
>> I move to csv file because originally the date where in csv file.
>> In addition, due to the fact that, as you told me, read.csv is a special
>> case of read.table, I prefer start to learn from the simplest one.
>> After that, I will try also the *.txt format.
>>
>> with read.csv, something strange happened:
>>
>> This us now the file:
>>
>> date,st1,st2,st3,
>> 10/1/1998 0:00,0.6,0,0
>> 10/1/1998 1:00,0.2,0.2,0.2
>> 10/1/1998 2:00,0.6,0.2,0.4
>> 10/1/1998 3:00,0,0,0.6
>> 10/1/1998 4:00,0,0,0
>> 10/1/1998 5:00,0,0,0
>> 10/1/1998 6:00,0,0,0
>> 10/1/1998 7:00,0.2,0,0
>> 10/1/1998 8:00,0.6,0.2,0
>> 10/1/1998 9:00,0.2,0.4,0.4
>> 10/1/1998 10:00,0,0.4,0.2
>>
>> When I apply:
>> MyData <- read.csv(file="obs_prec.csv",header=TRUE, sep=",")
>>
>> this is the results:
>>
>> 10/1/1998 0:000.60.000.0 NA
>> 210/1/1998 1:000.20.200.2 NA
>> 310/1/1998 2:000.60.200.4 NA
>> 410/1/1998 3:000.00.000.6 NA
>> 510/1/1998 4:000.00.000.0 NA
>> 610/1/1998 5:000.00.000.0 NA
>> 710/1/1998 6:000.00.000.0 NA
>> 810/1/1998 7:000.20.000.0 NA
>>
>> I do not understand why.
>> Something wrong with date?
>>
>> really really thanks,
>> I appreciate a lot all your helps.
>>
>> Diedro
>>
>>
>> Diego
>>
>>
>> On 31 July 2018 at 01:25, MacQueen, Don  wrote:
>>>
>>> Or, without removing the first line
>>>   dadf <- read.table("xxx.txt", stringsAsFactors=FALSE, skip=1)
>>>
>>> Another alternative,
>>>dadf$datetime <- as.POSIXct(paste(dadf$V1,dadf$V2))
>>> since the dates appear to be in the default format.
>>> (I generally prefer to work with datetimes in POSIXct class rather than
>>> POSIXlt class)
>>>
>>> -Don
>>>
>>> --
>>> Don MacQueen
>>> Lawrence Livermore National Laboratory
>>> 7000 East Ave., L-627
>>> Livermore, CA 94550
>>> 925-423-1062
>>> Lab cell 925-724-7509
>>>
>>>
>>>
>>> On 7/30/18, 4:03 PM, "R-help on behalf of Jim Lemon"
>>>  wrote:
>>>
>>> Hi Diego,
>>> You may have to do some conversion as you have three fields in the
>>> first line using the default space separator and five fields in
>>> subsequent lines. If the first line doesn't contain any important
>>> data
>>> you can just delete it or replace it with a meaningful header line
>>> with five fields and save the file under another name.
>>>
>>> It looks as thought you have date-time as two fields. If so, you can
>>> just read the first field if you only want the date:
>>>
>>> # assume you have removed the first line
>>> dadf<-read.table("xxx.txt",stringsAsFactors=FALSE
>>> dadf$date<-as.Date(dadf$V1,format="%Y-%m-%d")
>>>
>>> If you want the date/time:
>>>
>>> dadf$datetime<-strptime(paste(dadf$V1,dadf$V2),format="%Y-%m-%d
>>> %H:%M:%S")
>>>
>>> Jim
>>>
>>> On Tue, Jul 31, 2018 at 12:29 AM, Diego Avesani
>>>  wrote:
>>> > Dear all,
>>> >
>>> > I am dealing with the reading of a *.txt file.
>>> > The txt file the following shape:
>>> >
>>> > 103001930 103001580 103001530
>>> > 1998-10-01 00:00:00 0.6 0 0
>>> > 1998-10-01 01:00:00 0.2 0.2 0.2
>>> > 1998-10-01 02:00:00 0.6 0.2 0.4
>>> > 1998-10-01 03:00:00 0 0 0.6
>>> > 1998-10-01 04:00:00 0 0 0
>>> > 1998-10-01 05:00:00 0 0 0
>>> > 1998-10-01 06:00:00 0 0 0
>>> > 1998-10-01 07:00:00 0.2 0 0
>>> >
>>> > If it is possible I have a coupe of questions, which will sound
>>> stupid but
>>> > they are important to me in order to understand ho R deal with file
>>> or date.
>>> >
>>> > 1) Do I have to convert it to a *csv file?
>>> > 2) Can a deal with space and not ","
>>> > 3) How can I read date?
>>> >
>>> > thanks a lot to all of you,
>>> > Thanks
>>> >
>>> >
>>> > Diego
>>> >
>>> > [[alternative HTML version deleted]]
>>> >
>>> > __
>>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> > PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> > and provide commented, minimal, self-contained, reproducible code.
>>>
>>> 

Re: [R] read txt file - date - no space

2018-07-30 Thread MacQueen, Don via R-help
Or, without removing the first line
  dadf <- read.table("xxx.txt", stringsAsFactors=FALSE, skip=1)

Another alternative,
   dadf$datetime <- as.POSIXct(paste(dadf$V1,dadf$V2))
since the dates appear to be in the default format.
(I generally prefer to work with datetimes in POSIXct class rather than POSIXlt 
class)

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 7/30/18, 4:03 PM, "R-help on behalf of Jim Lemon" 
 wrote:

Hi Diego,
You may have to do some conversion as you have three fields in the
first line using the default space separator and five fields in
subsequent lines. If the first line doesn't contain any important data
you can just delete it or replace it with a meaningful header line
with five fields and save the file under another name.

It looks as thought you have date-time as two fields. If so, you can
just read the first field if you only want the date:

# assume you have removed the first line
dadf<-read.table("xxx.txt",stringsAsFactors=FALSE
dadf$date<-as.Date(dadf$V1,format="%Y-%m-%d")

If you want the date/time:

dadf$datetime<-strptime(paste(dadf$V1,dadf$V2),format="%Y-%m-%d %H:%M:%S")

Jim

On Tue, Jul 31, 2018 at 12:29 AM, Diego Avesani  
wrote:
> Dear all,
>
> I am dealing with the reading of a *.txt file.
> The txt file the following shape:
>
> 103001930 103001580 103001530
> 1998-10-01 00:00:00 0.6 0 0
> 1998-10-01 01:00:00 0.2 0.2 0.2
> 1998-10-01 02:00:00 0.6 0.2 0.4
> 1998-10-01 03:00:00 0 0 0.6
> 1998-10-01 04:00:00 0 0 0
> 1998-10-01 05:00:00 0 0 0
> 1998-10-01 06:00:00 0 0 0
> 1998-10-01 07:00:00 0.2 0 0
>
> If it is possible I have a coupe of questions, which will sound stupid but
> they are important to me in order to understand ho R deal with file or 
date.
>
> 1) Do I have to convert it to a *csv file?
> 2) Can a deal with space and not ","
> 3) How can I read date?
>
> thanks a lot to all of you,
> Thanks
>
>
> Diego
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read txt file - date - no space

2018-07-30 Thread Jim Lemon
Hi Diego,
You may have to do some conversion as you have three fields in the
first line using the default space separator and five fields in
subsequent lines. If the first line doesn't contain any important data
you can just delete it or replace it with a meaningful header line
with five fields and save the file under another name.

It looks as thought you have date-time as two fields. If so, you can
just read the first field if you only want the date:

# assume you have removed the first line
dadf<-read.table("xxx.txt",stringsAsFactors=FALSE
dadf$date<-as.Date(dadf$V1,format="%Y-%m-%d")

If you want the date/time:

dadf$datetime<-strptime(paste(dadf$V1,dadf$V2),format="%Y-%m-%d %H:%M:%S")

Jim

On Tue, Jul 31, 2018 at 12:29 AM, Diego Avesani  wrote:
> Dear all,
>
> I am dealing with the reading of a *.txt file.
> The txt file the following shape:
>
> 103001930 103001580 103001530
> 1998-10-01 00:00:00 0.6 0 0
> 1998-10-01 01:00:00 0.2 0.2 0.2
> 1998-10-01 02:00:00 0.6 0.2 0.4
> 1998-10-01 03:00:00 0 0 0.6
> 1998-10-01 04:00:00 0 0 0
> 1998-10-01 05:00:00 0 0 0
> 1998-10-01 06:00:00 0 0 0
> 1998-10-01 07:00:00 0.2 0 0
>
> If it is possible I have a coupe of questions, which will sound stupid but
> they are important to me in order to understand ho R deal with file or date.
>
> 1) Do I have to convert it to a *csv file?
> 2) Can a deal with space and not ","
> 3) How can I read date?
>
> thanks a lot to all of you,
> Thanks
>
>
> Diego
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read txt file - date - no space

2018-07-30 Thread Jeff Newmiller
1) No. 

2) The read.csv function is a s special case use of the more general read.table 
function that can handle any simple field separator.

3) Read the data in as character (I recommend using the stringsAsFactors=FALSE 
argument to read.table) and convert to an appropriate type from that form. e.g. 
[1]

[1] https://www.r-bloggers.com/using-dates-and-times-in-r/


On July 30, 2018 7:29:05 AM PDT, Diego Avesani  wrote:
>Dear all,
>
>I am dealing with the reading of a *.txt file.
>The txt file the following shape:
>
>103001930 103001580 103001530
>1998-10-01 00:00:00 0.6 0 0
>1998-10-01 01:00:00 0.2 0.2 0.2
>1998-10-01 02:00:00 0.6 0.2 0.4
>1998-10-01 03:00:00 0 0 0.6
>1998-10-01 04:00:00 0 0 0
>1998-10-01 05:00:00 0 0 0
>1998-10-01 06:00:00 0 0 0
>1998-10-01 07:00:00 0.2 0 0
>
>If it is possible I have a coupe of questions, which will sound stupid
>but
>they are important to me in order to understand ho R deal with file or
>date.
>
>1) Do I have to convert it to a *csv file?
>2) Can a deal with space and not ","
>3) How can I read date?
>
>thanks a lot to all of you,
>Thanks
>
>
>Diego
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] read txt file - date - no space

2018-07-30 Thread Diego Avesani
Dear all,

I am dealing with the reading of a *.txt file.
The txt file the following shape:

103001930 103001580 103001530
1998-10-01 00:00:00 0.6 0 0
1998-10-01 01:00:00 0.2 0.2 0.2
1998-10-01 02:00:00 0.6 0.2 0.4
1998-10-01 03:00:00 0 0 0.6
1998-10-01 04:00:00 0 0 0
1998-10-01 05:00:00 0 0 0
1998-10-01 06:00:00 0 0 0
1998-10-01 07:00:00 0.2 0 0

If it is possible I have a coupe of questions, which will sound stupid but
they are important to me in order to understand ho R deal with file or date.

1) Do I have to convert it to a *csv file?
2) Can a deal with space and not ","
3) How can I read date?

thanks a lot to all of you,
Thanks


Diego

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors [RESOLVED]

2018-07-19 Thread Rich Shepard

On Thu, 19 Jul 2018, David Winsemius wrote:


You can use format to only display the time portion of a datetime object.
format( Sys.time(), "%H:%M")
[1] "13:57"
You can append the current date to a "time-only" character value and as.POSIXct 
will do that for you:
as.POSIXct("00:00", format="%H:%M")
[1] "2018-07-19 PDT"
as.POSIXct(c("00:00", "00:01"), format="%H:%M")
[1] "2018-07-19 00:00:00 PDT" "2018-07-19 00:01:00 PDT"


David,

  I read about these in my R books and on web pages. I kept looking for a
time data type analogous to as.Date, as.character, and as.numeric. That's
what sent me in the wrong direction.


There is a difftime-class in base R And the lubridate package defines a
duration class. It's not a package I use, and I cannot tell off the top of
my head what it thinks the difference might be between a "time-span" and a
"duration".


  Good to know for the future.

  BTW, in a much earlier response you questioned why there were highly
negative elevations. Good question, because those should have been NAs and I
don't know how I let them in the data I manually extracted from PDF reports
from the USGS.

Best regards,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors [RESOLVED]

2018-07-19 Thread David Winsemius


> On Jul 19, 2018, at 1:21 PM, Rich Shepard  wrote:
> 
> On Thu, 19 Jul 2018, David Winsemius wrote:
> 
>> I took the code that I offered earlier and replaced allyears with wy2018:
> 
>>   date  timeelev myDate  myTime
>> 1 2017-10-01 00:00 290.298 2017-10-01 2017-10-01 00:00:00
>> 2 2017-10-01 00:30 290.301 2017-10-01 2017-10-01 00:30:00
>> 3 2017-10-01 01:00 290.304 2017-10-01 2017-10-01 01:00:00
>> 4 2017-10-01 01:30 290.295 2017-10-01 2017-10-01 01:30:00
>> 5 2017-10-01 02:00 290.292 2017-10-01 2017-10-01 02:00:00
>> 6 2017-10-01 02:30 290.289 2017-10-01 2017-10-01 02:30:00
>> 7 2017-10-01 03:00 290.289 2017-10-01 2017-10-01 03:00:00
>> 8 2017-10-01 03:30 290.289 2017-10-01 2017-10-01 03:30:00
>> 9 2017-10-01 04:00 290.280 2017-10-01 2017-10-01 04:00:00
>> 
>>> str(wy2018)
>> 'data.frame':9 obs. of  5 variables:
>> $ date  : Factor w/ 1 level "2017-10-01": 1 1 1 1 1 1 1 1 1
>> $ time  : Factor w/ 9 levels "00:00","00:30",..: 1 2 3 4 5 6 7 8 9
>> $ elev  : num  290 290 290 290 290 ...
>> $ myDate: Date, format: "2017-10-01" "2017-10-01" ...
>> $ myTime: POSIXct, format: "2017-10-01 00:00:00" "2017-10-01 00:30:00" ...
> 
> David,
> 
>  Thank you. I see the results in the dataframe structure although I still
> don't understand all the reasons. The 'myTime' column confirms what I
> thought: that there is no separate time data type. I'll use what you taught
> me an move on with the analyses.

You can use format to only display the time portion of a datetime object. 

format( Sys.time(), "%H:%M")
[1] "13:57"

You can append the current date to a "time-only" character value and as.POSIXct 
will do that for you:

as.POSIXct("00:00", format="%H:%M")
[1] "2018-07-19 PDT"

> as.POSIXct(c("00:00", "00:01"), format="%H:%M")
[1] "2018-07-19 00:00:00 PDT" "2018-07-19 00:01:00 PDT"

There is a difftime-class in base R


And the lubridate package defines a duration class. It's not a package I use, 
and I cannot tell off the top of my head what it thinks the difference might be 
between a "time-span" and a "duration".

Best of luck.

> 
> Best regards,
> 
> Rich
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors [RESOLVED]

2018-07-19 Thread Rich Shepard

On Thu, 19 Jul 2018, David Winsemius wrote:


I took the code that I offered earlier and replaced allyears with wy2018:



   date  timeelev myDate  myTime
1 2017-10-01 00:00 290.298 2017-10-01 2017-10-01 00:00:00
2 2017-10-01 00:30 290.301 2017-10-01 2017-10-01 00:30:00
3 2017-10-01 01:00 290.304 2017-10-01 2017-10-01 01:00:00
4 2017-10-01 01:30 290.295 2017-10-01 2017-10-01 01:30:00
5 2017-10-01 02:00 290.292 2017-10-01 2017-10-01 02:00:00
6 2017-10-01 02:30 290.289 2017-10-01 2017-10-01 02:30:00
7 2017-10-01 03:00 290.289 2017-10-01 2017-10-01 03:00:00
8 2017-10-01 03:30 290.289 2017-10-01 2017-10-01 03:30:00
9 2017-10-01 04:00 290.280 2017-10-01 2017-10-01 04:00:00


str(wy2018)

'data.frame':   9 obs. of  5 variables:
$ date  : Factor w/ 1 level "2017-10-01": 1 1 1 1 1 1 1 1 1
$ time  : Factor w/ 9 levels "00:00","00:30",..: 1 2 3 4 5 6 7 8 9
$ elev  : num  290 290 290 290 290 ...
$ myDate: Date, format: "2017-10-01" "2017-10-01" ...
$ myTime: POSIXct, format: "2017-10-01 00:00:00" "2017-10-01 00:30:00" ...


David,

  Thank you. I see the results in the dataframe structure although I still
don't understand all the reasons. The 'myTime' column confirms what I
thought: that there is no separate time data type. I'll use what you taught
me an move on with the analyses.

Best regards,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-19 Thread David Winsemius


> On Jul 19, 2018, at 12:33 PM, Rich Shepard  wrote:
> 
> On Thu, 19 Jul 2018, Rich Shepard wrote:
> 
>> I have the date and elev columns converted from factors to date and
>> numeric, respectively, but still have not learned how to convert the time.
> 
>  With this dataframe structure,
> 
> str(wy2018)
> 'data.frame': 12592 obs. of  3 variables:
> $ date: Date, format: "2017-10-01" "2017-10-01" ...
> $ time: chr  "00:00" "00:30" "01:00" "01:30" ...
> $ elev: num  290 290 290 290 290 ...
> 
> what is my syntax error using chron() to convert the time column?

I have no idea. I think reaching for chron is not needed.
> 
> wy2018$time <- chron(times=wy2018$time)
> Error in convert.times(times., fmt) : format h:m:s may be incorrect
> In addition: Warning message:
> In unpaste(times, sep = fmt$sep, fnames = fmt$periods, nfields = 3) :
>  12592 entries set to NA due to wrong number of fields

That error suggests you needed either to add ":00" on hte end of your hh:mm 
formated data or provide a format string.

> wy2018$myTime <- chron(times= paste(wy2018$time, ":00") )


> str(wy2018)
'data.frame':   9 obs. of  5 variables:
 $ date  : Factor w/ 1 level "2017-10-01": 1 1 1 1 1 1 1 1 1
 $ time  : Factor w/ 9 levels "00:00","00:30",..: 1 2 3 4 5 6 7 8 9
 $ elev  : num  290 290 290 290 290 ...
 $ myDate: Date, format: "2017-10-01" "2017-10-01" ...
 $ myTime: 'times' num  00:00:00 00:30:00 01:00:00 01:30:00 02:00:00 ...
  ..- attr(*, "format")= chr "h:m:s"

But I think that is not the right way to go.

> 
> 
>  Adding a format as either %h:%m or just h:m makes no difference.
> 
> Rich
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-19 Thread David Winsemius


> On Jul 19, 2018, at 10:02 AM, Rich Shepard  wrote:
> 
> On Thu, 19 Jul 2018, Rich Shepard wrote:
> 
>> Since then I reformatted the file to two fields: date-time and elevation.
>> If anyone wants a copy send me a message off the list and I'll respond with
>> the modified file attached.
> 
>  This is a mistake. The file needs commas separating each field.
> 
>  I have the date and elev columns converted from factors to date and
> numeric, respectively, but still have not learned how to convert the time.
> 
>  The source data file (head):
> date,time,elev
> 2017-10-01,00:00,290.298
> 2017-10-01,00:30,290.301
> 2017-10-01,01:00,290.304
> 2017-10-01,01:30,290.295
> 2017-10-01,02:00,290.292
> 2017-10-01,02:30,290.289
> 2017-10-01,03:00,290.289
> 2017-10-01,03:30,290.289
> 2017-10-01,04:00,290.28

I took the code that I offered earlier and replaced allyears with wy2018:

> txt <- "date,time,elev
+ 2017-10-01,00:00,290.298
+ 2017-10-01,00:30,290.301
+ 2017-10-01,01:00,290.304
+ 2017-10-01,01:30,290.295
+ 2017-10-01,02:00,290.292
+ 2017-10-01,02:30,290.289
+ 2017-10-01,03:00,290.289
+ 2017-10-01,03:30,290.289

+ 2017-10-01,04:00,290.28"
> wy2018 <- read.table(text=txt, header = T, sep = ',')

> wy2018 $myDate <- as.Date(as.character(wy2018 $date))
> wy2018 $myTime <- as.POSIXct(paste(wy2018 $date, wy2018 $time))
> wy2018
date  timeelev myDate  myTime
1 2017-10-01 00:00 290.298 2017-10-01 2017-10-01 00:00:00
2 2017-10-01 00:30 290.301 2017-10-01 2017-10-01 00:30:00
3 2017-10-01 01:00 290.304 2017-10-01 2017-10-01 01:00:00
4 2017-10-01 01:30 290.295 2017-10-01 2017-10-01 01:30:00
5 2017-10-01 02:00 290.292 2017-10-01 2017-10-01 02:00:00
6 2017-10-01 02:30 290.289 2017-10-01 2017-10-01 02:30:00
7 2017-10-01 03:00 290.289 2017-10-01 2017-10-01 03:00:00
8 2017-10-01 03:30 290.289 2017-10-01 2017-10-01 03:30:00
9 2017-10-01 04:00 290.280 2017-10-01 2017-10-01 04:00:00

> str(wy2018)
'data.frame':   9 obs. of  5 variables:
 $ date  : Factor w/ 1 level "2017-10-01": 1 1 1 1 1 1 1 1 1
 $ time  : Factor w/ 9 levels "00:00","00:30",..: 1 2 3 4 5 6 7 8 9
 $ elev  : num  290 290 290 290 290 ...
 $ myDate: Date, format: "2017-10-01" "2017-10-01" ...
 $ myTime: POSIXct, format: "2017-10-01 00:00:00" "2017-10-01 00:30:00" ...

> 
>  These commands read the file and convert the date and elev columns:
> wy2018 <- read.table('sh-2018.dat', header = T, sep = ',')
> wy2018$date <- as.Date(as.character(wy2018$date, format='y-m-d'))
> head(wy2018)
>date timeelev
> 1 2017-10-01   01 290.298
> 2 2017-10-01   01 290.301
> 3 2017-10-01   01 290.304
> 4 2017-10-01   01 290.295
> 5 2017-10-01   01 290.292
> 6 2017-10-01   01 290.289
> 
>  My attempts using chron() for the time column keep failing; e.g., 
> wy2018$time <- chron(wy2018$time, format='h:m')
> str(wy2018)
> 'data.frame': 12592 obs. of  3 variables:
> $ date: Date, format: "2017-10-01" "2017-10-01" ...
> $ time: 'dates' num  01 01 01 01 01 01 01 01 01 01 ...
>  ..- attr(*, "format")= chr "h:m"
>  ..- attr(*, "origin")= Named num  1 1 1970
>  .. ..- attr(*, "names")= chr  "month" "day" "year"
> $ elev: num  290 290 290 290 290 ...
> 
>  Also, when I tried to use chron() for both the date and time columns of
> the dataframe these failed, too.
> 
>  Please teach me how to read the data sources and produce dataframe columns
> of date, time, and numeric.
> 
> Rich
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-19 Thread Rich Shepard

On Thu, 19 Jul 2018, Rich Shepard wrote:


I have the date and elev columns converted from factors to date and
numeric, respectively, but still have not learned how to convert the time.


  With this dataframe structure,

str(wy2018)
'data.frame':   12592 obs. of  3 variables:
 $ date: Date, format: "2017-10-01" "2017-10-01" ...
 $ time: chr  "00:00" "00:30" "01:00" "01:30" ...
 $ elev: num  290 290 290 290 290 ...

what is my syntax error using chron() to convert the time column?

wy2018$time <- chron(times=wy2018$time)
Error in convert.times(times., fmt) : format h:m:s may be incorrect
In addition: Warning message:
In unpaste(times, sep = fmt$sep, fnames = fmt$periods, nfields = 3) :
  12592 entries set to NA due to wrong number of fields


  Adding a format as either %h:%m or just h:m makes no difference.

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-19 Thread Rich Shepard

On Thu, 19 Jul 2018, Rich Shepard wrote:


Since then I reformatted the file to two fields: date-time and elevation.
If anyone wants a copy send me a message off the list and I'll respond with
the modified file attached.


  This is a mistake. The file needs commas separating each field.

  I have the date and elev columns converted from factors to date and
numeric, respectively, but still have not learned how to convert the time.

  The source data file (head):
date,time,elev
2017-10-01,00:00,290.298
2017-10-01,00:30,290.301
2017-10-01,01:00,290.304
2017-10-01,01:30,290.295
2017-10-01,02:00,290.292
2017-10-01,02:30,290.289
2017-10-01,03:00,290.289
2017-10-01,03:30,290.289
2017-10-01,04:00,290.28

  These commands read the file and convert the date and elev columns:
wy2018 <- read.table('sh-2018.dat', header = T, sep = ',')
wy2018$date <- as.Date(as.character(wy2018$date, format='y-m-d'))
head(wy2018)
date timeelev
1 2017-10-01   01 290.298
2 2017-10-01   01 290.301
3 2017-10-01   01 290.304
4 2017-10-01   01 290.295
5 2017-10-01   01 290.292
6 2017-10-01   01 290.289

  My attempts using chron() for the time column keep failing; e.g., 
wy2018$time <- chron(wy2018$time, format='h:m')

str(wy2018)
'data.frame':   12592 obs. of  3 variables:
 $ date: Date, format: "2017-10-01" "2017-10-01" ...
 $ time: 'dates' num  01 01 01 01 01 01 01 01 01 01 ...
  ..- attr(*, "format")= chr "h:m"
  ..- attr(*, "origin")= Named num  1 1 1970
  .. ..- attr(*, "names")= chr  "month" "day" "year"
 $ elev: num  290 290 290 290 290 ...

  Also, when I tried to use chron() for both the date and time columns of
the dataframe these failed, too.

  Please teach me how to read the data sources and produce dataframe columns
of date, time, and numeric.

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-19 Thread Rich Shepard

On Thu, 19 Jul 2018, Rich Shepard wrote:


 I put a zipped data file at this URL:



  Since then I reformatted the file to two fields: date-time and elevation.
If anyone wants a copy send me a message off the list and I'll respond with
the modified file attached.

  Because time zone doesn't matter for a single location I'm looking at how
to use chron(). I've downloaded the PDF from CRAN and am trying to apply it
correctly so the dataframe contains two columns: date-time and elevation.
Will probably be asking for help in correctly using chron().

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-19 Thread Rich Shepard

On Wed, 18 Jul 2018, Rich Shepard wrote:


If you would suggest how many would be an acceptably large number I'll be
happy to put that on a 'cloud' sharing site and provide the URL to it.


  I put a zipped data file at this URL:


  It will stay there for 5 days.

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-18 Thread Rich Shepard

On Wed, 18 Jul 2018, David Winsemius wrote:


It's not so much as factors but rather in a form that paste() will coerce
to character so you cna get the automatic format


David,

  Now I understand.


Maybe you need to add a format string. It might force some of your pasted
date+time values to NA but at least you would be able to identify the
original values and perhaps fix errors.


  Thinking about the data I realize that rather than separate date and time
columns what's needed is a datetime string. I'll add the format string in
the morning and work on this.


You really should include a large snapshot of data that will allow
reproducibility.


  I'll certainly do this. With hourly and half-hourly data from 1989-June
2018 (but missing all of 1992) there are more than 400K rows in the raw data
file. If you would suggest how many would be an acceptably large number I'll
be happy to put that on a 'cloud' sharing site and provide the URL to it.

Best regards,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-18 Thread David Winsemius


> On Jul 18, 2018, at 4:07 PM, Rich Shepard  wrote:
> 
> On Wed, 18 Jul 2018, David Winsemius wrote:
> 
>> I would not destroy the possibility of using the original values:
> 
> David,
> 
>  What are the benefits of keeping date and time as factors?
> 
>>> allyears$myDate <- as.Date(as.character(allyears$date))
>>> allyears$myTime <- as.POSIXct(paste(allyears$date, allyears$time))


It's not so much as factors but rather in a form that paste() will coerce to 
character so you cna get the automatic format

> 
>  The latter command is not working on the full (402415 rows in the allyears
> data set):
> 
> allyears$myTime <- as.POSIXct(paste(allyears$date, allyears$time))
> Error in as.POSIXlt.character(x, tz, ...) :
>  character string is not in a standard unambiguous format

Maybe you need to add a format string. It might force some of your pasted 
date+time values to NA but at least you would be able to identify the original 
values and perhaps fix errors.

You really should include a large snapshot of data that will allow 
reproducibility.


> 
>> It's spelled `as.numeric`,
> 
>  Ah, I missed that. Thank you.
> 
>> ... but I'm having difficulty thinking about what sort of elevation (or would
>> that be "depth") would be be measured by "-376293888000369098752".
> 
>  I also was curious about that figure and grep doesn't find it in the
> original data file so I've no idea where R-3.5.0 came up with it.
> 
>  I'll read more about the POSIX datetime functions.
> 
> Thanks again,
> 
> Rich
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-18 Thread Rich Shepard

On Wed, 18 Jul 2018, David Winsemius wrote:


I would not destroy the possibility of using the original values:


David,

  What are the benefits of keeping date and time as factors?


allyears$myDate <- as.Date(as.character(allyears$date))
allyears$myTime <- as.POSIXct(paste(allyears$date, allyears$time))


  The latter command is not working on the full (402415 rows in the allyears
data set):

allyears$myTime <- as.POSIXct(paste(allyears$date, allyears$time))
Error in as.POSIXlt.character(x, tz, ...) :
  character string is not in a standard unambiguous format


It's spelled `as.numeric`,


  Ah, I missed that. Thank you.


... but I'm having difficulty thinking about what sort of elevation (or would
that be "depth") would be be measured by "-376293888000369098752".


  I also was curious about that figure and grep doesn't find it in the
original data file so I've no idea where R-3.5.0 came up with it.

  I'll read more about the POSIX datetime functions.

Thanks again,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Read in data table, change columns from factors

2018-07-18 Thread David Winsemius


> On Jul 18, 2018, at 2:50 PM, Rich Shepard  wrote:
> 
>  A set of data files have this format:
> 
> date,time,elev
> 1988-10-01,00:30,87.6849
> 1988-10-01,01:00,87.6849
> 1988-10-01,01:30,87.6849
> 1988-10-01,02:00,87.6879
> 1988-10-01,02:30,87.6879
> 1988-10-01,03:00,87.691
> 1988-10-01,03:30,87.694
> 
> Importing it with this command:
> 
> allyears <- read.table('allyears.dat', header = T, sep = ',')
> 
> produces this structure:
> 
> str(allyears)
> 'data.frame': 402414 obs. of  3 variables:
> $ date: Factor w/ 10230 levels "'data'","'date'",..:
> $ time: Factor w/ 1441 levels "'time'","00:00",..:
> $ elev: Factor w/ 4494 levels "'elev'","-376293888000369098752",..:
> 
>  Applying,
> allyears$date <- as.Date(as.character(allyears$date))
> changes the structure to
> str(allyears)
> 'data.frame': 402414 obs. of  3 variables:
> $ date: Date, format: "1988-10-01" "1988-10-01" ...
> $ time: Factor w/ 1441 levels "'time'","00:00",..:
> $ elev: Factor w/ 4494 levels "'elev'","-376293888000369098752",..:
> 
>  I've not found the proper syntax to change time to a POSIXct time format
> nor the elev to a numeric format.

I would not destroy the possibility of using the original values:

> allyears$myDate <- as.Date(as.character(allyears$date))
> allyears$myTime <- as.POSIXct(paste(allyears$date, allyears$time))
> allyears
date  timeelev myDate  myTime
1 1988-10-01 00:30 87.6849 1988-10-01 1988-10-01 00:30:00
2 1988-10-01 01:00 87.6849 1988-10-01 1988-10-01 01:00:00
3 1988-10-01 01:30 87.6849 1988-10-01 1988-10-01 01:30:00
4 1988-10-01 02:00 87.6879 1988-10-01 1988-10-01 02:00:00
5 1988-10-01 02:30 87.6879 1988-10-01 1988-10-01 02:30:00
6 1988-10-01 03:00  87.691 1988-10-01 1988-10-01 03:00:00
7 1988-10-01 03:30 87.694t 1988-10-01 1988-10-01 03:30:00

> 


> allyears$time <- as.POSIXct(as.character(allyears$time, format=%H:%M))
> Error: unexpected SPECIAL in "allyears$time <- 
> as.POSIXct(as.character(allyears$time, format=%H:%"
> 
> and
> 
> allyears$elev <- as.Numeric(allyears$elev)
> Error in as.Numeric(allyears$elev) : could not find function "as.Numeric"

It's spelled `as.numeric`, but I'm having difficulty thinking about what sort 
of elevation (or would that be "depth") would be be measured by 
"-376293888000369098752".


> 
>  I've read ?read.table and looked on the web but I'm not finding how to
> properly change the time and elev factors to H:M and fractional feet. A
> pointer to a resource is much appreciated.
> 
> Rich
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read in data table, change columns from factors

2018-07-18 Thread Rich Shepard

  A set of data files have this format:

date,time,elev
1988-10-01,00:30,87.6849
1988-10-01,01:00,87.6849
1988-10-01,01:30,87.6849
1988-10-01,02:00,87.6879
1988-10-01,02:30,87.6879
1988-10-01,03:00,87.691
1988-10-01,03:30,87.694

Importing it with this command:

allyears <- read.table('allyears.dat', header = T, sep = ',')

produces this structure:

str(allyears)
'data.frame':   402414 obs. of  3 variables:
 $ date: Factor w/ 10230 levels "'data'","'date'",..:
 $ time: Factor w/ 1441 levels "'time'","00:00",..:
 $ elev: Factor w/ 4494 levels "'elev'","-376293888000369098752",..:

  Applying,
allyears$date <- as.Date(as.character(allyears$date))
changes the structure to
str(allyears)
'data.frame':   402414 obs. of  3 variables:
 $ date: Date, format: "1988-10-01" "1988-10-01" ...
 $ time: Factor w/ 1441 levels "'time'","00:00",..:
 $ elev: Factor w/ 4494 levels "'elev'","-376293888000369098752",..:

  I've not found the proper syntax to change time to a POSIXct time format
nor the elev to a numeric format.

allyears$time <- as.POSIXct(as.character(allyears$time, format=%H:%M))
Error: unexpected SPECIAL in "allyears$time <- 
as.POSIXct(as.character(allyears$time, format=%H:%"

and

allyears$elev <- as.Numeric(allyears$elev)
Error in as.Numeric(allyears$elev) : could not find function "as.Numeric"

  I've read ?read.table and looked on the web but I'm not finding how to
properly change the time and elev factors to H:M and fractional feet. A
pointer to a resource is much appreciated.

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read .asc from web into R

2018-06-03 Thread David Winsemius



> On Jun 3, 2018, at 6:52 AM, Qian Yiting  wrote:
> 
> Hi All,
> 
> I am new to R. To import data with .asc ending from the web into R, I have 
> tried many functions for importing data but it came out not well.  The 
> problem may seem to be very basic but unfortunately I haven’t  found any 
> useful information somehow.  Which command should I use for that purpose?
> 
> Here ist the url of the data:
> https://moodle.lmu.de/pluginfile.php/218819/mod_resource/content/1/nba.asc

This URL requires authorization. You probably need to sign in with your 
username and password and download with a browser or FTP client. The 
instructions should be somewhere in their website (which is in German).


> 
> Thanks in advance!
> 
> Best regards,
> Yiting
> 
>   [[alternative HTML version deleted]]

R-help is a plain text mailing list. Please read these instructions as well as 
the instructions at https://moodle.lmu.de/
> 
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
David.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read .asc from web into R

2018-06-03 Thread Jeff Newmiller
Have you tried that url in a web browser? I encountered an access permission 
error. If you also encountered an error, then so would R. You need to download 
the file using appropriate access credentials (typ. through a web browser) and 
read it from disk.

FWIW the ".asc" extension is very nearly meaningless as to identifying the 
format of the data inside the file. The only useful information imparted by 
that extension is that you can use a text editor to view it and judge by 
inspection what the layout is. Originally that extension was used for storing 
the readable output of a program, which could be laid out in any form deemed 
readable by a human, with little regard for whether it would be 
machine-readable.

On June 3, 2018 7:52:58 AM MDT, Qian Yiting  wrote:
>Hi All,
>
>I am new to R. To import data with .asc ending from the web into R, I
>have tried many functions for importing data but it came out not well. 
>The problem may seem to be very basic but unfortunately I haven’t 
>found any useful information somehow.  Which command should I use for
>that purpose?
>
>Here ist the url of the data:
>https://moodle.lmu.de/pluginfile.php/218819/mod_resource/content/1/nba.asc
>
>Thanks in advance!
>
>Best regards,
>Yiting
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] read .asc from web into R

2018-06-03 Thread Qian Yiting
Hi All,

I am new to R. To import data with .asc ending from the web into R, I have 
tried many functions for importing data but it came out not well.  The problem 
may seem to be very basic but unfortunately I haven’t  found any useful 
information somehow.  Which command should I use for that purpose?

Here ist the url of the data:
https://moodle.lmu.de/pluginfile.php/218819/mod_resource/content/1/nba.asc

Thanks in advance!

Best regards,
Yiting

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read list of binary files and explore them

2017-04-29 Thread Boris Steipe
Given that, you can be certain that your file contains more than one or two 
numbers, thus your way of reading it must be wrong.

B.





> On Apr 29, 2017, at 11:34 AM, Ragia .  wrote:
> 
> 
> files size is 7682 kb
> 
> sorry for multiple emails
> 
> Ragia
> 
> 
> 
> 
> 
> From: Bert Gunter 
> Sent: Saturday, April 29, 2017 4:45 PM
> To: Ragia .; R-help
> Subject: Re: [R] read list of binary files and explore them
> 
> 1. Unless your comment is OT or personal, always reply to the list.
> 
> 2. What does your OS say about file size?
> 
> 3. Beyond this, I cannot help.
> 
> -- Bert
> 
> 
> 
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming along and 
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> 
> On Sat, Apr 29, 2017 at 6:38 AM, Ragia . 
> mailto:ragi...@hotmail.com>> wrote:
> 
> 
> lots  of thanks for answering, I guess I asked the question in wont way...
> 
> I did that, but some times I got one single reading( number) from the 
> file..other times two numbers, is there a way to be sure that I am reading it 
> correctly? what I know is not more than its float content .
> 
> 
> Ribrahim
> 
> 
> 
> 
> 
> From: Bert Gunter mailto:bgunter.4...@gmail.com>>
> Sent: Saturday, April 29, 2017 6:31 AM
> To: Ragia .
> Cc: r-help@r-project.org<mailto:r-help@r-project.org>
> Subject: Re: [R] read list of binary files and explore them
> 
> 
> ?readBin  (a search on "read binary files R" or similar would have found 
> this).
> 
> and please spend some time with the R import/export manual + tutorials
> to learn how to manipulate data in R. This list expects you to make an
> effort to do your own work before posting. See the posting guide below
> for details.
> 
> Cheers,
> Bert
> 
> 
> 
> 
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> 
> 
> On Fri, Apr 28, 2017 at 9:13 PM, Ragia . 
> mailto:ragi...@hotmail.com>> wrote:
>> 
>> Dear group,
>> 
>> I have  list of  4-byte float type files, the files are named f00, f01, f02 
>> till f99
>> 
>> 
>> kindly how can I read and explore them in R, merge the readings in a table 
>> or data frame
>> 
>> thanks in advance,
>> 
>> 
>> Ragia A. Ibrahim
>> 
>> 
>> 
>>[[alternative HTML version deleted]]
>> 
>> __
>> R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To 
>> UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
> 
> thz.ch/mailman/listinfo/r-help>
> stat.ethz.ch<http://stat.ethz.ch>
> The main R mailing list, for announcements about the development of R and the 
> availability of new code, questions and answers about problems and solutions 
> using R ...
> 
> 
> 
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read list of binary files and explore them

2017-04-29 Thread Bert Gunter
1. Unless your comment is OT or personal, always reply to the list.

2. What does your OS say about file size?

3. Beyond this, I cannot help.

-- Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Sat, Apr 29, 2017 at 6:38 AM, Ragia .  wrote:

>
> lots  of thanks for answering, I guess I asked the question in wont way...
>
> I did that, but some times I got one single reading( number) from the
> file..other times two numbers, is there a way to be sure that I am reading
> it correctly? what I know is not more than its float content .
>
>
> Ribrahim
>
>
>
>
> --
> *From:* Bert Gunter 
> *Sent:* Saturday, April 29, 2017 6:31 AM
> *To:* Ragia .
> *Cc:* r-help@r-project.org
> *Subject:* Re: [R] read list of binary files and explore them
>
>
>  ?readBin  (a search on "read binary files R" or similar would have found
> this).
>
> and please spend some time with the R import/export manual + tutorials
> to learn how to manipulate data in R. This list expects you to make an
> effort to do your own work before posting. See the posting guide below
> for details.
>
> Cheers,
> Bert
>
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Fri, Apr 28, 2017 at 9:13 PM, Ragia .  wrote:
> >
> > Dear group,
> >
> > I have  list of  4-byte float type files, the files are named f00, f01,
> f02 till f99
> >
> >
> > kindly how can I read and explore them in R, merge the readings in a
> table or data frame
> >
> > thanks in advance,
> >
> >
> > Ragia A. Ibrahim
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> R-help -- Main R Mailing List: Primary help - Homepage - SfS
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> stat.ethz.ch
> The main R mailing list, for announcements about the development of R and
> the availability of new code, questions and answers about problems and
> solutions using R ...
>
>
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   3   4   5   6   7   >