Re: [R-SIG-Mac] Some introductory questions

2020-09-08 Thread Adrian Dușa
Dear Mike,

I remember so very well the time when I struggled with exactly the same
things, reading a file seeming like an almost insurmountable task.
However, given this actually is very simple I can also understand the
reactions you got. Imagine every newbie asking these questions over
and over again, in a time where there is so much information out there to
figure it out quite easy.

The documentation might be a little cryptic, I give you that. But there are
so many other resources, most of them free, that you can read to understand
how this works. I would warmly recommend some of the contributed
introductory materials from:
https://cran.r-project.org/other-docs.html

There are also plenty of websites to teach R interactively, and all of them
offer this kind of information, without exception, since this really is
part of the very basics in R.

What I learned over the years is that help on this list is invaluable. But
all of the contributors share their own time, and help must be required in
such a way that it (at least) makes it obvious you did first try to do your
homework. Most of the time, asking the right question(s) reveals the answer
and at some point you will only need to browse past similar questions to
find the answer you want.

Linked to that, one other thing I learned is my question is almost never
unique and most likely somebody else asked something at least similar in
the past. Doing your homework also means trying to dig in the archives,
which is pretty easy these days using Google.

Should you make this effort and make it evident in your question that you
did try to read on your own, I'm sure it would be easy for other people to
point you in the right direction. Because this is almost always what I
need: a pointer, and then I can figure it out on my own.

Rest assured this is a very friendly email list, and I consider myself
lucky to be part of this community. Despite knowing this for so many years,
I still make mistakes and consume too much of others' time. But at least I
am aware of that, and extremely grateful for the help I get.

I hope this helps,
Adrian

On Tue, Sep 8, 2020 at 1:08 AM Mike Feher  wrote:

> Hi Peter,
>
> Here is a snippet of the code I was trying to start with:
>
> filepath1 <- file("/Users/michaelfeher/Documents/R
> Documents/COVID19/20200906-1822-total-cases-jones.data")
> filepath1
> TotalCasesJones <- read.table(filepath1)
>
> This definitely did not work for me.
>
> Mike
>
> On September 7, 2020 at 3:50:19 AM, peter dalgaard (pda...@gmail.com)
> wrote:
>
>
>
> > On 7 Sep 2020, at 07:09 , Ken Beath  wrote:
> >
> >> On 7 Sep 2020, at 9:31 am, Mike Feher  wrote:
> >
> [snip]
> >> 4. I tried to read in a set of dummy space-delimited data saved in an
> >> absolute path on my computer, but it would not work. I tried something
> in
> >> another path that did not have a subfolder with a space in it (I.e. I
> plan
> >> on storing my data in a folder called “R Documents” or something
> similar)
> >> and that didn’t work either, so I’m still wondering whether or not (a)
> >> things have to be in the library location (it seems like you could
> >> customize that) and (b) whether R recognizes spaces in file paths.
> >>
> >
> > Try using file.choose() to locate files using a dialog and it will return
> the full name. Spaces shouldn’t matter provided that everything is enclosed
> in quotes. Most people don’t use absolute references. They set the working
> directory and then just use the name of the file. See under the Misc menu.
>
> Also, how do you "read in" the data? Usually, read.table() or somesuch
> would be involved, although RStudio has an "Import data" functionality.
>
> -pd
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk Priv: pda...@gmail.com
>
> [[alternative HTML version deleted]]
>
> ___
> R-SIG-Mac mailing list
> R-SIG-Mac@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania
https://adriandusa.eu

[[alternative HTML version deleted]]

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


Re: [R-SIG-Mac] Some introductory questions

2020-09-08 Thread peter dalgaard
Not work how? You need to tell us what kind of errors you see, otherwise, we 
can only guess.

I'd lose the file() construct. It sets up a connection object, which can be 
less than useful when read.table reads the file several time in order to 
decipher the column structure of the file.

So plain

filepath1 <- "/Users/michaelfeher/Documents/R 
Documents/COVID19/20200906-1822-total-cases-jones.data"

should be OK, provided that the file actually exists. In particular, check that 
the space in "R Documents" really is a space and not something that just looks 
like a space (no-break space is a common culprit).

If you can read the file, but it comes out weird, then you need to diddle the 
arguments to read.table, e.g.

> filepath <- "~/tmp/R files/test.data"
> read.table(filepath)
  V1 V2
1  x  y
2  1  2
3  3  7
4  9 13
> read.table(filepath, header=TRUE)
  x  y
1 1  2
2 3  7
3 9 13


-pd


> On 8 Sep 2020, at 00:04 , Mike Feher  wrote:
> 
> Hi Peter,
> 
> Here is a snippet of the code I was trying to start with:
> 
> filepath1 <- file("/Users/michaelfeher/Documents/R 
> Documents/COVID19/20200906-1822-total-cases-jones.data")
> filepath1
> TotalCasesJones <- read.table(filepath1)
> 
> This definitely did not work for me.
> 
> Mike
> 
> On September 7, 2020 at 3:50:19 AM, peter dalgaard (pda...@gmail.com) wrote:
> 
>> 
>> 
>> > On 7 Sep 2020, at 07:09 , Ken Beath  wrote: 
>> >  
>> >> On 7 Sep 2020, at 9:31 am, Mike Feher  wrote: 
>> >  
>> [snip] 
>> >> 4. I tried to read in a set of dummy space-delimited data saved in an 
>> >> absolute path on my computer, but it would not work. I tried something in 
>> >> another path that did not have a subfolder with a space in it (I.e. I 
>> >> plan 
>> >> on storing my data in a folder called “R Documents” or something similar) 
>> >> and that didn’t work either, so I’m still wondering whether or not (a) 
>> >> things have to be in the library location (it seems like you could 
>> >> customize that) and (b) whether R recognizes spaces in file paths. 
>> >>  
>> >  
>> > Try using file.choose() to locate files using a dialog and it will return 
>> > the full name. Spaces shouldn’t matter provided that everything is 
>> > enclosed in quotes. Most people don’t use absolute references. They set 
>> > the working directory and then just use the name of the file. See under 
>> > the Misc menu.  
>> 
>> Also, how do you "read in" the data? Usually, read.table() or somesuch would 
>> be involved, although RStudio has an "Import data" functionality.  
>> 
>> -pd 
>> 
>> --  
>> Peter Dalgaard, Professor, 
>> Center for Statistics, Copenhagen Business School 
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark 
>> Phone: (+45)38153501 
>> Office: A 4.23 
>> Email: pd@cbs.dk  Priv: pda...@gmail.com

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac