This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unique(df[, c("a", "c")]) | |
or | |
df <- subset(df, select = c(a,c)) | |
or to drop | |
df <- subset(df, select = -c(a,c)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
names(df) <- c("column1","column2") | |
or by name | |
names(df)[names( df)=="Los_Angeles"]<-"LA" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df <- read.csv("data.csv") | |
df$new_column1<- ifelse(df$c3 == "A",1,0) | |
df$new_column2<- ifelse(df$c4 == "B",1,0) | |
df$new_column3 <-ifelse(df$c5 == "C" & df$c6 = D, 1, 0) | |
via @BrianAbelson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df2 <- paste (df1$col1, df1$col2, sep = "_") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
descending | |
df[with(df, order(-a)), ] | |
or | |
df[order(-df$col1),] | |
ascending |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggsave(ratings, file="ratings.svg") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Symbol Meaning Example | |
%d day as a number (0-31) 01-31 | |
%a abbreviated weekday, Mon | |
%A unabbreviated weekday, Monday | |
%m month (00-12), 00-12 | |
%b abbreviated month, Jan | |
%B unabbreviated month, January | |
%y 2-digit year | |
%Y 4-digit year |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^(?!http).+ | |
\.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nice for then doing aggregate functions | |
for(t in unique(df$colToExplode)) { | |
a[paste("",t,sep="")] <- ifelse(df$colToExplode==t,1,0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function returns quater scores from Wikipedia Super Bown pages | |
get.scores<-function(numeral) { | |
# Base URL for Wikipedia | |
wp.url<-getURL(paste("http://en.wikipedia.org/wiki/Super_Bowl_",numeral,sep="")) | |
wp.data<-htmlTreeParse(wp.url, useInternalNodes=TRUE) | |
score.html<-getNodeSet(wp.data,"//table[@style='background-color:transparent;']") | |
score.table<-readHTMLTable(score.html[[1]]) | |
score.table<-transform(score.table, SB=numeral) | |
return(score.table) | |
} |
OlderNewer