Your verification ID is: guDlT7MCuIOFFHSbB3jPFN5QLaQ Big Computing: Simple Problems in R cause big headaches....Always check your variable class

Monday, March 2, 2015

Simple Problems in R cause big headaches....Always check your variable class

Recently a frined of mine who is a newer user to R was having some problems getting his data to graph properly. He went around and around with it, but simply could not figure out what was going on. This is one of the tough things about R. It will usually run your code even if there is a little problem with what your are doing. I have been stuck for hours because of something I forgot to do. The most common reason I end up having a problem is that the data in not of the class I thought is was. So the code was doing everything it was supposed to do correctly, but I had not either changed the class of the data or verified that it was correct anywhere in my code. When you are developing I highly reccomend that you do that. It will save you a ton of time and stress.
I will show this issue because it does a great job of showing the problem.
First, let me read in the data.
data<-read.csv("/Users/kmettler/Downloads/Kirk.csv")
head(data)
##    Time
## 1 13:10
## 2 12:00
## 3 11:50
## 4 10:30
## 5  8:40
## 6  9:00
Now he wanted to plot these times.
plot(table(data$Time),main="December Incident Reports by Time of Day", xlab="Time of Day in Hours",ylab="Number of Reports",lwd=4,col=8)
plot of chunk unnamed-chunk-2
It runs. However, you will notice it does not look right. The problems is that time is not of the right class and needs to be converted to the right one
class(data[,1])
## [1] "factor"
data2<-as.data.frame(strptime(data[,1], format="%H:%M"))
hist(as.numeric(data2[,1]),main="December Incident Reports by Time of Day", xlab="Time of Day in Hours",ylab="Number of Reports")
plot of chunk unnamed-chunk-3
Now that look way better. Now all that has to be done is the analysis.

1 comment:

  1. Microsoft has actively sustained what they call “a blistering pace of innovation” and, whilst listening to user needs, they continue to update Power BI with monthly updates. Microsoft Power BI is new, but excitingly it’s evolving virtually on a monthly basis. So just when you realize how brilliant the Power BI tool is, you suddenly discovered it’s just got even better! Data Bear is one of the many companies helping clients with this powerful self-service business intelligence (BI) offering, and it didn’t take long for their team to identify Power BI as a serious game changer. Specializing in business intelligence consulting, Data Bear founder, Johann Joubert believes Power BI has become the single most powerful tool for businesses to use to ensure the full range of businesses are ahead of the rapidly changing BI world and the opportunities it offers.

    Find More : Power BI Reports

    ReplyDelete