Skip to content

Instantly share code, notes, and snippets.

@iracooke
Last active August 29, 2015 14:07
Show Gist options
  • Save iracooke/ba2acafb5c21a784f12f to your computer and use it in GitHub Desktop.
Save iracooke/ba2acafb5c21a784f12f to your computer and use it in GitHub Desktop.
R Snippets
toxin_counts = c(2273,2306,2235,19,183,61,210)
taxa = c("Gastropods","Snakes","Arachnids","Mammals","Jellyfish","Amphibians","other")
df = data.frame(toxin_counts,taxa)
pie(df$toxin_counts,labels=df$taxa)
# Create example data
abc = c("a","c","b")
one23 = c(1,3,2)
df = data.frame(abc,one23,stringsAsFactors=FALSE)
# Generate a sort index based on the abc column
df.sortidx = sort(df$abc,index.return=TRUE)$ix
# Recorder the original data frame based on the sort index
sorteddf = df[df.sortidx,]
# Create example data
abc = c("a","c","b")
one23 = c(1,3,2)
df = data.frame(abc,one23,stringsAsFactors=FALSE)
# Select data for which the numeric column (one23) is greater than 1
df[which(df$one23>1),]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment