Created
November 14, 2015 00:07
-
-
Save somerealnumbers/631265dd076ef620a84b to your computer and use it in GitHub Desktop.
Basic work with an R Data Frame
This file contains hidden or 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
| # creating an R data frame | |
| sim_data = data.frame(X = rnorm(n = 10), | |
| Y = rnorm(n = 10), | |
| Z = rnorm(n = 10)) | |
| # select column j | |
| sim_data[,1] | |
| # ...or by name | |
| sim_data['X'] | |
| # select row j | |
| sim_data[1,] | |
| # select data point i,j | |
| sim_data[1,1] | |
| # additional data | |
| more_sim_data = data.frame(X = rnorm(n = 10), | |
| Y = rnorm(n = 10), | |
| Z = rnorm(n = 10)) | |
| # add more rows | |
| sim_data = rbind(sim_data, more_sim_data) | |
| # apply a function over each column | |
| apply(sim_data, 2, function(x) mean(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment