Created
March 7, 2014 15:28
-
-
Save randyzwitch/9413532 to your computer and use it in GitHub Desktop.
DataFrame method on composite type
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
function DataFrame(array::Array{TWEETS, 1}) | |
#Empty df as container for results | |
resultdf = DataFrame() | |
#Get array of field names as symbols from composite type | |
cols = names(TWEETS) | |
#For each field in composite type... | |
for column in cols | |
#Temp array to hold results | |
temp = {} | |
#Loop over array of composite type, get individual field value from outer loop value | |
for value in array | |
push!(temp, getfield(value, column)) | |
end | |
#Append each column to df | |
resultdf = hcat(resultdf, temp) | |
end | |
#Use cols array above to properly name df columns | |
names!(resultdf, cols) | |
return resultdf | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment