[R] Why Does R Print out strange record?

arthur brogard abrogard at yahoo.com
Tue Dec 20 21:42:18 CET 2016




Yep. Okay.  This better?  It's gone to the list I think? And I found the plain text option right before my eyes there at the bottom of the page.

thanks for your help.

 




________________________________
From: Richard M. Heiberger <rmh at temple.edu>

Sent: Wednesday, 21 December 2016, 6:57
Subject: Re: [R] Why Does R Print out strange record?


The convention on this email list is to always reply to the list, not
just the person who replied to you.
Many people comment on the same questions with interesting different
perspectives.

Start with two things to read.
1. the posting guide linked at the bottom of each email on the list.
2. The introductory manual at system.file("../../doc/manual/R-intro.pdf")

Specifics: almost everything in R is vectorized, meaning you usually
do not need explicit loops.

I don't use yahoo email so I don't know how to set it to plain text.
I am sure it is possible.
do a web search.



>
>  Thank you for your help.
>
>  I'm sorry about the html. I use yahoo mail and I can find no way to switch
> it off if it is sending html.  I wasn't aware it was doing that.
>
> I'm looking into installing and using perhaps thunderbird or something.
> Their web site doesn't seem to make a pronouncement about that aspect,
> either.  If you have a recommendation please let me know.
>
> I obviously have a tremendous amount to learn with this R.
>
> I've very old fashioned and pedestrian in my thoughts on what to do.  I'm
> thinking I must go down the list and process each value some way but I think
> R has functions that do this for you. Such as your diff().
>
> Your code has produced all the values I see when I list out 'rates'.   Now
> I'm thinking to loop through and extract all the ones I'm interested in. Are
> you saying there's a better way to do such things just as you did it with
> diff() ?
>
> regards,
>
> ab
>
> p.s. if you wish me to stop communicating until i've got this html thing
> sorted out just say so.
>
>
>
>
>
> ________________________________
> From: Richard M. Heiberger <rmh at temple.edu>

> Cc: "r-help at r-project.org" <r-help at r-project.org>
> Sent: Tuesday, 20 December 2016, 15:29
> Subject: Re: [R] Why Does R Print out strange record?
>
> You have read your Date variable in as a character variable, which was
> coerced to a factor.
> You probably wanted the values to be interpreted as dates.  example of
> what to do is below.
> Note that the date-factor levels are sorted alphabetically, which is
> almost certainly not what you want.
>
> In addition, please do not use HTML mail.  R-help is plain-text list
> and R code often gets scrambled beyond recognition.
>
> Attaching a data.frame is very bad style, and will get you into
> trouble in the future.  Again, see below for a recommendation.
>
>
>
> rates <- read.csv(text="
>     Date, Int
> Feb-2012, .04
> Mar-2012, .045
> Apr-2012, .042
> May-2012, .038
> Jun-2012, .051
> ",
> header=TRUE,
> colClasses=c("character","numeric"))
>
> rates
> sapply(rates, class)
>
>
> ## dates are one of the most difficult computing concepts to get
> ## right.  your dates are month and year, not including day-of-month,
> ## and are therefore even more difficult.  I am putting them all on
> ## the first of the month, and forcing a common time zone to bypass
> ## the daylight savings time problems.
>
> rates$Date <- strptime(paste0("1-", rates$Date), format="%d-%b-%Y",
> tz="UTC")
> ## you will need to read
> ## ?as.POSIXct
> ## ?strptime
>
> ## the rest of your calculations can be done more easily with
> vectorized arithmetic.
>
> mysize <- nrow(rates)
> rates$thisone <- c(diff(rates$Int), NA)
> rates$nextone <- c(diff(rates$Int, lag=2), NA, NA)
> rates$lastone <- (rates$thisone + rates$nextone)/6.5*1000
> rates
>
> On Mon, Dec 19, 2016 at 8:08 PM, arthur brogard via R-help
> <r-help at r-project.org> wrote:
>> I have this bit of code:
>> rates=read.csv("Rates2.csv")
>> attach(rates)
>> mysize <- nrow(rates)
>> count <- 0
>> for(i in 1:(mysize - 3)) {
>> #print(i)
>> thisday <- Date[i]
>> thisone <- Int[i+1] - Int[i]
>> nextone <- Int[i+2] - Int[i]
>> lastone <- thisone + nextone
>> lastone <- lastone/6.5
>> lastone <- lastone * 1000
>>
>> #print("thisone")
>> #print(thisone)
>> #print("nextone")
>> #print(nextone)
>>
>> if (lastone >0){
>> print(thisday)
>> print("dollars saved per $100,000")
>> print(lastone)
>> count = count + 1
>> }
>> }
>> which generally works alright until I put the last bit in about 'thisday'
>> since then I get a display with such as this in it:
>> [1] "dollars saved per $100,000"
>> [1] 9.230769
>> [1] Feb-2012
>> 689 Levels: Apr-1959 Apr-1960 Apr-1961 Apr-1962 ... Sep-2015
>> [1] "dollars saved per $100,000"
>> [1] 18.46154
>> [1] Jun-2015
>> 689 Levels: Apr-1959 Apr-1960 Apr-1961 Apr-1962 ... Sep-2015
>> [1] "dollars saved per $100,000"
>> [1] 21.53846
>>
>> This word 'Levels'  is not present in the data.
>>
>> Can anyone help, tell me what is happening here?
>>
>>
>>  ================================
>>
>> Can you handle truth ?
>>
>> Barbara Walker: Woman's Encyclopedia of Myths and Secrets
>>
>> What it is really about:
>> https://www.youtube.com/watch?v=sYKAgAfYJZE
>>
>> The bald truth:
>> https://www.youtube.com/watch?v=kevNDOCbKxE
>>
>> https://www.youtube.com/watch?v=fbfdsMdbcfA
>>
>> Sanity:
>> Those terrible Russians:
>> https://www.youtube.com/watch?v=VZsjoiFfpXM
>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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.
>
>
>



More information about the R-help mailing list