Skip to content

Instantly share code, notes, and snippets.

@briandk
Created January 15, 2015 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandk/5e96c0c4edea7c940d8f to your computer and use it in GitHub Desktop.
Save briandk/5e96c0c4edea7c940d8f to your computer and use it in GitHub Desktop.
Using the bracket notation ("[") as a function in R
x = list("red",
"green",
"blue")
print(x)
# [[1]]
# [1] "red"
#
# [[2]]
# [1] "green"
#
# [[3]]
# [1] "blue"
sapply(X = x,
FUN = "[")
# [1] "red" "green" "blue"
myData = data.frame(cholesterol = 240)
typeof(y)
# "list"
typeof(
sapply(
X = myData,
FUN = "["
)
)
# "double"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment