Skip to content

Instantly share code, notes, and snippets.

@stephlocke
Created July 24, 2017 15:27
Show Gist options
  • Save stephlocke/af70721e8befb131e9257780a5f083d5 to your computer and use it in GitHub Desktop.
Save stephlocke/af70721e8befb131e9257780a5f083d5 to your computer and use it in GitHub Desktop.
a<-50:1
a[1:5]
a[a<25]
a[-1]
a[-(40:50)]
a[c(FALSE,TRUE)]
b<-c(11:50,1:10)
b[b %% 2]
b[as.logical(b %% 2)]
b[(b %% 2) == 1]
sort(b)
order(b)
df<-data.frame(a=1:3,b=3:1)
df
df[1:2,2]
df[1:2,1:2]
df[-3,]
df[ , "a"]
df[df[ , "a"]<3, ]
df[df$a<3, ]
df[1:2,-1]
df[df$a<3 & df$b>1, ]
?iris
View(iris)
iris[ , ]
iris[ 1:5 , ]
iris[ , 1:2 ]
iris[ , "Sepal.Length"]
iris[ , c("Sepal.Length","Sepal.Width")]
iris$Sepal.Width <5.8
avg <- mean(iris$Sepal.Width)
rowsToKeep <- iris$Sepal.Width<avg
irisKept <- iris[rowsToKeep, ]
View(iris)
library(readr)
write_csv(iris, "iris.csv")
write.csv(iris,"2iris.csv",row.names = FALSE) #equivalent
read_csv("iris.csv")
library(haven)
irisDF<-iris
colnames(irisDF)<-c("SepalLength","SepalWidth",
"PetalLength", "PetalWidth",
"Species")
haven::write_dta(irisDF, "iris.dta",version = 13)
@stephlocke
Copy link
Author

That's so great!
🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment