Skip to content

Instantly share code, notes, and snippets.

@randyzwitch
Created March 7, 2014 15:28
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 randyzwitch/9413532 to your computer and use it in GitHub Desktop.
Save randyzwitch/9413532 to your computer and use it in GitHub Desktop.
DataFrame method on composite type
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