Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code style #4

Open
hadley opened this issue Aug 4, 2015 · 1 comment
Open

Code style #4

hadley opened this issue Aug 4, 2015 · 1 comment

Comments

@hadley
Copy link

hadley commented Aug 4, 2015

A bit of whitespace and indenting makes code like this easier to read:

soul <- mutate(soul,QD1gr=cut(QD1, breaks=c(0,30,40,50,60,70,80,99), include.lowest=T),
               QD2gr=cut(QD2, breaks=c(0,10,20,50  ,99), include.lowest=T),prop.res =QD2/QD1,
               prop.gr=cut(prop.res, breaks=c(0,0.25,0.5,1,5.5),include.lowest=T))

# vs

soul <- mutate(soul,
  QD1gr = cut(QD1, breaks = c(0, 30, 40, 50, 60, 70, 80, 99), include.lowest = T),
  QD2gr = cut(QD2, breaks = c(0, 10, 20, 50, 99), include.lowest = T),
  prop.res = QD2 / QD1,
  prop.gr = cut(prop.res, breaks = c(0, 0.25, 0.5, 1 , 5.5), include.lowest = T)
)
@hadley
Copy link
Author

hadley commented Aug 4, 2015

Adopting a consistent code style makes it much easier to scan the doc. This block jumped out at me because of the indented pieces, but I don't think the indentation actually means anything.

aux <- read.csv("incomePC.csv", header=T)
aux <- subset(aux, X=='Estimate')
aux[,4] <- as.numeric(as.character(aux[,4]))
  aux1 <- subset(aux,select=-c(1,3),subset=!community%in%c('Gary','Philadelphia'))
  aux2 <- apply(subset(aux,community=='Gary',select=-c(1,2,3)),2,mean)
  aux2 <- data.frame(community='Gary',t(aux2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant