Google Visualization API. Graphs are not displaying in gsp pages - grails-2.0

I am developing application with grails. Below is the list of Program I use.
- Groovy/Grails Tool Suite Version: 3.5.1.RELEASE Platform: Eclipse Kepler SR2 (4.3.2)
- Grails 2.3.8
- Java : jdk1.6.0_45
my problem is having installed google visualization plugin by specifying in the BuildConfig.groovy with the code below
plugins {
compile ":google-visualization:0.7"
}
and tried the sample below but the chart are not displaying.
there seems to be no error what so ever. What I suspect is that the application does not recognise the tag .
anybody has come across this problem, your help would be very much appreciated.
Cheers,
Sura
<%# page import="org.grails.plugins.google.visualization.data.Cell; org.grails.plugins.google.visualization.util.DateUtil" %>
<html>
<head>
<title>Google Visualization API plugin</title>
<meta name="layout" content="main" />
<gvisualization:apiImport/>
</head>
<body>
<%
def calendarColumns = [['date', 'Date'], ['number', 'Won/Loss']]
def calendarData = [[DateUtil.createDate(2012, 3, 13), 37032], [DateUtil.createDate(2012, 3, 14), 38024], [DateUtil.createDate(2012, 3, 15), 38024], [DateUtil.createDate(2012, 3, 16), 38108], [DateUtil.createDate(2012, 3, 17), 38229]]
def timelineColumns = [['string', 'President'], ['date', 'Start'], ['date', 'End']]
def timelineData = [['Washington', DateUtil.createDate(1789, 3, 29), DateUtil.createDate(1797, 2, 3)], ['Adams', DateUtil.createDate(1797, 2, 3), DateUtil.createDate(1801, 2, 3)], ['Jefferson', DateUtil.createDate(1801, 2, 3), DateUtil.createDate(1809, 2, 3)]]
def myDailyActivitiesColumns = [['string', 'Task'], ['number', 'Hours per Day']]
def myDailyActivitiesData = [['Work', 11], ['Eat', 2], ['Commute', 2], ['Watch TV', 2], ['Sleep', 7]]
def companyPerformanceColumns = [['string', 'Year'], ['number', 'Sales'], ['number', 'Expenses']]
def companyPerformanceData = [['2004', 1000, 400], ['2005', 1170, 460], ['2006', 660, 1120], ['2007', 1030, 540]]
def yearlyExpensesColumns = [['string', 'Year'], ['number', 'Expenses'], ['number', 'Sales']]
def yearlyExpensesData = [['2004', 1000, 900], ['2005', 1170, 1000], ['2006', 660, 660], ['2007', 1030, 1000]]
def weightByAgeColumns = [['number', 'Age'], ['number', 'Weight']]
def weightByAgeData = [[8, 12], [4, 5.5], [11, 14], [4, 5], [3, 3.5], [6.5, 7]]
def countByDayColumns = [['string', 'Day'], ['number', ''], ['number', ''], ['number', ''], ['number', '']]
def countByDayData = [['Mon', 20, 28, 38, 45], ['Tues', 31, 38, 55, 66], ['Wed', 50, 55, 77, 80], ['Thurs', 50, 77, 66, 77], ['Fri', 15, 66, 22, 68]]
def monthlyCoffeeProdByCountryColumns = [['string', 'Month'], ['number', 'Bolivia'], ['number', 'Ecuador'], ['number', 'Madagascar'], ['number', 'Papua Guinea'], ['number', 'Rwanda'], ['number', 'Average']]
def monthlyCoffeeProdByCountryData = [['2004/05', 165, 938, 522, 998, 450, 614.6], ['2005/06', 135, 1120, 599, 1268, 288, 682], ['2006/07', 157, 1167, 587, 807, 397, 623], ['2007/08', 139, 1110, 615, 968, 215, 609.4], ['2008/09', 136, 691, 629, 1026, 366, 569.6]]
def revenueAndLicensesColumns = [['number', 'Revenue'], ['number', 'Licenses']]
def revenueAndLicensesData = [[435, 132], [438, 131], [512, 137], [460, 142], [491, 140], [487, 139], [552, 147], [511, 146], [505, 151], [509, 149]]
def gainersLoserColumns = [['string', 'Name'], ['number', ''], ['number', ''], ['number', ''], ['number', '']]
def gainersLoserData = [['Gainers', 10, 30, 45, 60], ['Losers', 20, 35, 25, 45]]
def systemPerformanceColumns = [['string', 'Label'], ['number', 'Value']]
def systemPerformanceData = [['Memory', 80], ['CPU', 55], ['Network', 68]]
def employeeColumns = [['string', 'Name'], ['string', 'Salary'], ['boolean', 'Full Time Employee']]
def employeeData = [['Mike', '$10,000', true], ['Jim', '$8,000', false], ['Alice', '$12,500', true], ['Bob', '$7,000', true]]
def mapColumns = [['number', 'Lat'], ['number', 'Lon'], ['string', 'Name']]
def mapData = [[37.4232, -122.0853, 'Work'], [37.4289, -122.1697, 'University'], [37.6153, -122.3900, 'Airport'], [37.4422, -122.1731, 'Shopping']]
def pensColumns = [['date', 'Date'], ['number', 'Sold Pencils'], ['string', 'title1'], ['string', 'text1'], ['number', 'Sold Pens'], ['string', 'title2'], ['string', 'text2']]
def pensData = [[DateUtil.createDate(2008, 1, 1), 30000, null, null, 40645, null, null], [DateUtil.createDate(2008, 1, 2), 14045, null, null, 20374, null, null], [DateUtil.createDate(2008, 1, 3), 55022, null, null, 50766, null, null], [DateUtil.createDate(2008, 1, 4), 75284, null, null, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'], [DateUtil.createDate(2008, 1, 5), 41476, 'Bought Pens','Bought 200k pens', 66467, null, null], [DateUtil.createDate(2008, 1, 6), 33322, null, null, 39463, null, null]]
def orgColumns = [['string', 'Name'], ['string', 'Manager'], ['string', 'ToolTip']]
def orgData = [[new Cell(value: 'Mike', label: 'Mike<div style="color:red; font-style:italic">President</div>'), '', 'The President'], [new Cell(value: 'Jim', label: 'Jim<div style="color:red; font-style:italic">Vice President<div>'), 'Mike', 'VP'], ['Alice', 'Mike', ''], ['Bob', 'Jim', 'Bob Sponge'], ['Carol', 'Bob', '']]
def populationColumns = [['string', '', 'Country'], ['number', 'Population (mil)', 'a'], ['number', 'Area (km2)', 'b']]
def populationData = [['CN', 1324, 9640821], ['IN', 1133, 3287263], ['US', 304, 9629091], ['ID', 232, 1904569], ['BR', 187, 8514877]]
def popularityColumns = [['string', 'Country'], ['number', 'Popularity']]
def popularityData = [['Germany', 200], ['United States', 300], ['Brazil', 400], ['Canada', 500], ['France', 600], ['RU', 700]]
def fruitColumns = [['string', 'Fruit'], ['date', 'Date'], ['number', 'Sales'], ['number', 'Expenses'], ['string', 'Location']]
def fruitData = [['Apples', DateUtil.createDate(1988, 0, 1), 1000, 300, 'East'], ['Oranges', DateUtil.createDate(1988, 0, 1), 1150, 200, 'West'], ['Bananas', DateUtil.createDate(1988, 0, 1), 300, 250, 'West'], ['Apples', DateUtil.createDate(1989, 6, 1), 1200, 400, 'East'], ['Oranges', DateUtil.createDate(1989, 6, 1), 750, 150, 'West'], ['Bananas', DateUtil.createDate(1989, 6, 1), 788, 617, 'West']]
def marketByRegionColumns = [['string', 'Region'], ['string', 'Parent'], ['number', 'Market trade volume (size)'], ['number', 'Market increase/decrease (color)']]
def marketByRegionData = [['Global', null, 0, 0], ['America', 'Global', 0, 0], ['Europe', 'Global', 0, 0], ['Asia', 'Global', 0, 0], ['Australia', 'Global', 0, 0], ['Africa', 'Global', 0, 0], ['Brazil', 'America', 11, 10], ['USA', 'America', 52, 31], ['Mexico', 'America', 24, 12], ['Canada', 'America', 16, -23], ['France', 'Europe', 42, -11], ['Germany', 'Europe', 31, -2], ['Sweden', 'Europe', 22, -13], ['Italy', 'Europe', 17, 4], ['UK', 'Europe', 21, -5], ['China', 'Asia', 36, 4], ['Japan', 'Asia', 20, -12], ['India', 'Asia', 40, 63], ['Laos', 'Asia', 4, 34], ['Mongolia', 'Asia', 1, -5], ['Israel', 'Asia', 12, 24], ['Iran', 'Asia', 18, 13], ['Pakistan', 'Asia', 11, -52], ['Egypt', 'Africa', 21, 0], ['S. Africa', 'Africa', 30, 43], ['Sudan', 'Africa', 12, 2], ['Congo', 'Africa', 10, 12], ['Zair', 'Africa', 8, 10]]
def accumulatedRatingColumns = [['string', 'Director (Year)'], ['number', 'Rotten Tomatoes'], ['number', 'IMDB']]
def accumulatedRatingData = [['Alfred Hitchcock (1935)', 8.4, 7.9], ['Ralph Thomas (1959)', 6.9, 6.5], ['Don Sharp (1978)',6.5, 6.4], ['James Hawes (2008)', 4.4, 6.2]]
def lifeExpectancyFertilityRateColumns =[['string', 'ID'], ['number', 'Life Expectancy'], ['number', 'Fertility Rate'], ['string', 'Region'], ['number', 'Population']]
def lifeExpectancyFertilityRateData = [['CAN', 80.66, 1.67, 'North America', 33739900], ['DEU', 79.84, 1.36, 'Europe', 81902307], ['DNK', 78.6, 1.84, 'Europe', 5523095], ['EGY', 72.73, 2.78, 'Middle East', 79716203], ['GBR', 80.05, 2, 'Europe', 61801570], ['IRN', 72.49, 1.7, 'Middle East', 73137148], ['IRQ', 68.09, 4.77, 'Middle East', 31090763], ['ISR', 81.55, 2.96, 'Middle East', 7485600], ['RUS', 68.6, 1.54, 'Europe', 141850000], ['USA', 78.09, 2.05, 'North America', 307007000]]
def candlestickOptions = [hollowIsRising: true]
%>
<script type="text/javascript">
function selectHandler(e) {
alert('A table row was selected');
}
function readyHandler(e) {
console.log('Table is ready');
}
</script>
<h2>Google Visualization API Examples</h2>
<gvisualization:pieCoreChart elementId="piechart" title="My Daily Activities" width="${450}" height="${300}" columns="${myDailyActivitiesColumns}" data="${myDailyActivitiesData}" />
<gvisualization:imagePieChart elementId="imagepiechart" width="${430}" height="${240}" title="My Daily Activities" columns="${myDailyActivitiesColumns}" data="${myDailyActivitiesData}" />
<gvisualization:barCoreChart elementId="barchart" title="Company Performance" width="${400}" height="${240}" vAxis="${new Expando(title: 'Year', titleColor: 'red')}" columns="${companyPerformanceColumns}" data="${companyPerformanceData}" />
<gvisualization:imageBarChart elementId="imagebarchart" width="${400}" height="${240}" min="${0}" columns="${companyPerformanceColumns}" data="${companyPerformanceData}" />
<gvisualization:bubbleCoreChart elementId="bubblechart" title="Correlation between life expectancy, fertility rate and population of some world countries (2010)" hAxis="${new Expando(title: 'Life Expectancy')}" vAxis="${new Expando(title: 'Fertility Rate')}" bubble="${new Expando(textStyle: '{fontSize: 11}')}" columns="${lifeExpectancyFertilityRateColumns}" data="${lifeExpectancyFertilityRateData}" />
<gvisualization:columnCoreChart elementId="columnchart" title="Company Performance" width="${400}" height="${240}" hAxis="${new Expando(title: 'Year', titleColor: 'red')}" columns="${companyPerformanceColumns}" data="${companyPerformanceData}" />
<gvisualization:areaCoreChart elementId="areachart" title="Company Performance" width="${400}" height="${240}" hAxis="${new Expando(title: 'Year', titleColor: 'red')}" columns="${companyPerformanceColumns}" data="${companyPerformanceData}" />
<gvisualization:imageAreaChart elementId="imageareachart" width="${400}" height="${240}" min="${300}" max="${1400}" title="Yearly Expenses and Sales" columns="${yearlyExpensesColumns}" data="${yearlyExpensesData}" />
<gvisualization:lineCoreChart elementId="linechart" width="${400}" height="${240}" title="Company Performance" columns="${companyPerformanceColumns}" data="${companyPerformanceData}" />
<gvisualization:imageLineChart elementId="imagelinechart" width="${400}" height="${240}" min="${0}" columns="${companyPerformanceColumns}" data="${companyPerformanceData}" />
<gvisualization:scatterCoreChart elementId="scatterchart" width="${400}" height="${240}" title="Age vs. Weight comparison" hAxis="${new Expando(title: 'Age', minValue: 0, maxValue: 15)}" vAxis="${new Expando(title: 'Weight', minValue: 0, maxValue: 15)}" legend="none" columns="${weightByAgeColumns}" data="${weightByAgeData}" />
<gvisualization:steppedAreaCoreChart elementId="steppedareachart" width="${400}" height="${240}" title="The decline of \'The 39 Steps\'" vAxis="${new Expando(title: 'Accumulated Rating')}" isStacked="${true}" columns="${accumulatedRatingColumns}" data="${accumulatedRatingData}" />
<gvisualization:candlestickCoreChart elementId="candlestickchart" legend="none" columns="${countByDayColumns}" data="${countByDayData}" candlestick="${new Expando(candlestickOptions)}" />
<gvisualization:comboCoreChart elementId="combochart" title="Monthly Coffee Production by Country" vAxis="${new Expando(title: 'Cups')}" hAxis="${new Expando(title: 'Month')}" seriesType="bars" series="${new Expando(5: new Expando(type: 'line'))}" columns="${monthlyCoffeeProdByCountryColumns}" data="${monthlyCoffeeProdByCountryData}" />
<gvisualization:imageSparkLine elementId="imagesparkline" width="${120}" height="${40}" showAxisLines="${false}" showValueLabels="${false}" labelPosition="left" columns="${revenueAndLicensesColumns}" data="${revenueAndLicensesData}" />
<gvisualization:imageCandlestickChart elementId="imagecandlestickchart" columns="${gainersLoserColumns}" data="${gainersLoserData}" />
<gvisualization:gauge elementId="gauge" width="${400}" height="${120}" redFrom="${90}" redTo="${100}" yellowFrom="${75}" yellowTo="${90}" minorTicks="${5}" columns="${systemPerformanceColumns}" data="${systemPerformanceData}" />
<gvisualization:table elementId="table" width="${400}" height="${130}" columns="${employeeColumns}" data="${employeeData}" select="selectHandler" ready="readyHandler"/>
<gvisualization:map elementId="map" columns="${mapColumns}" data="${mapData}" />
<gvisualization:annotatedTimeLine elementId="annotatedtimeline" columns="${pensColumns}" data="${pensData}" />
<gvisualization:orgChart elementId="orgchart" allowHtml="${true}" columns="${orgColumns}" data="${orgData}" />
<gvisualization:intensityMap elementId="intensitymap" columns="${populationColumns}" data="${populationData}" />
<gvisualization:geoMap elementId="geomap" columns="${popularityColumns}" data="${popularityData}" />
<gvisualization:geoChart elementId="geochart" width="${556}" height="${347}" columns="${popularityColumns}" data="${popularityData}" />
<gvisualization:motionChart elementId="motionchart" columns="${fruitColumns}" data="${fruitData}" />
<gvisualization:treeMap elementId="treemap" minColor="#f00" midColor="#ddd" maxColor="#0d0" headerHeight="${15}" fontColor="black" showScale="${true}" columns="${marketByRegionColumns}" data="${marketByRegionData}" />
<gvisualization:timeLine elementId="timeline" columns="${timelineColumns}" data="${timelineData}" />
<gvisualization:calendarChart elementId="calendarchart" columns="${calendarColumns}" data="${calendarData}" />
<table cellpadding="2" cellspacing="0">
<tr>
<td>
Pie Chart
</td>
<td>
<div id="piechart"></div>
</td>
</tr>
<tr>
<td>
Pie Chart (Image)
</td>
<td>
<div id="imagepiechart"></div>
</td>
</tr>
<tr>
<td>
Bar Chart
</td>
<td>
<div id="barchart"></div>
</td>
</tr>
<tr>
<td>
Bar Chart (Image)
</td>
<td>
<div id="imagebarchart"></div>
</td>
</tr>
<tr>
<td>
Bubble Chart
</td>
<td>
<div id="bubblechart" style="width: 900px; height: 500px;"></div>
</td>
</tr>
<tr>
<td>
Column Chart
</td>
<td>
<div id="columnchart"></div>
</td>
</tr>
<tr>
<td>
Area Chart
</td>
<td>
<div id="areachart"></div>
</td>
</tr>
<tr>
<td>
Area Chart (Image)
</td>
<td>
<div id="imageareachart"></div>
</td>
</tr>
<tr>
<td>
Line Chart
</td>
<td>
<div id="linechart"></div>
</td>
</tr>
<tr>
<td>
Line Chart (Image)
</td>
<td>
<div id="imagelinechart"></div>
</td>
</tr>
<tr>
<td>
Scatter Chart
</td>
<td>
<div id="scatterchart"></div>
</td>
</tr>
<tr>
<td>
Stepped Area Chart
</td>
<td>
<div id="steppedareachart"></div>
</td>
</tr>
<tr>
<td>
Sparkline (Image)
</td>
<td>
<div id="imagesparkline"></div>
</td>
</tr>
<tr>
<td>
Candlestick Chart
</td>
<td>
<div id="candlestickchart" style="width: 300px; height: 300px;"></div>
</td>
</tr>
<tr>
<td>
Candlestick Chart (Image)
</td>
<td>
<div id="imagecandlestickchart" style='width: 300px; height: 300px;'></div>
</td>
</tr>
<tr>
<td>
Combo Chart
</td>
<td>
<div id="combochart" style="width: 700px; height: 400px;"></div>
</td>
</tr>
<tr>
<td>
Gauge
</td>
<td>
<div id="gauge"></div>
</td>
</tr>
<tr>
<td>
Table
</td>
<td>
<div id="table"></div>
</td>
</tr>
<tr>
<td>
Map
</td>
<td>
<div id="map" style="width: 400px; height: 300px"></div>
</td>
</tr>
<tr>
<td>
Annotated Time Line
</td>
<td>
<div id="annotatedtimeline" style='width: 700px; height: 240px;'></div>
</td>
</tr>
<tr>
<td>
Organizational Chart
</td>
<td>
<div id="orgchart"></div>
</td>
</tr>
<tr>
<td>
Intensity Map
</td>
<td>
<div id="intensitymap"></div>
</td>
</tr>
<tr>
<td>
Geo Map
</td>
<td>
<div id="geomap"></div>
</td>
</tr>
<tr>
<td>
Geo Chart
</td>
<td>
<div id="geochart"></div>
</td>
</tr>
<tr>
<td>
Motion Chart
</td>
<td>
<div id="motionchart"></div>
</td>
</tr>
<tr>
<td>
Tree Map
</td>
<td>
<div id="treemap" style="width: 900px; height: 500px;"></div>
</td>
</tr>
<tr>
<td>
Timeline
</td>
<td>
<div id="timeline"></div>
</td>
</tr>
<tr>
<td>
Calendar
</td>
<td>
<div id="calendarchart"></div>
</td>
</tr>
</table>
</body>
</html>

To fix this problem I looked up the internet and here is the solution.
Modify the _visualization_javascripts.gsp file in goggle visualisation api as follows:
changed from <%=row %> TO <%=raw(row) %>
changed from <%=visualizationData.options%> TO <%=raw(visualizationData.options)%>

Try adding this to you Config.groovy.
Found this on the commit history from the developer itself.
googleVisualization.grails.views.gsp.codecs.scriptlet = "none"
~Dixie

Related

How to solve error when using adorn_totals function in R?

I get the following message of error when using janitor::adorn_totals("row"):
"Error in adorn_totals(., "row") :
trying to re-add a totals dimension that is already been added"
Here is the head of my dataset :
structure(list(code_1 = c("M01", "C03", "M99", "C05", "O01",
"C07"), regroupement_elsan = c("Gastro", "Ophtalmo", "Divers médecine",
"Gynéco", "Accouchements", "bouche et dents"), actes_2019 = c(9179,
5589, 6024, 4150, 4028, 3458), actes_2020 = c(7933, 4167, 3740,
2994, 3348, 2206), actes_2021 = c(6504, 5505, 4682, 3376, 3226,
3035), sejours_2019 = c(1631, 2502, 1028, 852, 1455, 1288), sejours_2020 = c(1335,
1819, 726, 574, 1371, 801), sejours_2021 = c(1109, 2416, 825,
657, 1259, 1106), tx_0_nuit_2019 = c("3.92397302268547", "90.7673860911271",
"32.9766536964981", "57.5117370892019", "0.206185567010309",
"98.9130434782609"), tx_0_nuit_2020 = c("3.29588014981273", "92.9081913139087",
"47.1074380165289", "59.581881533101", "0.291757840991977", "99.250936329588"
), tx_0_nuit_2021 = c("3.6068530207394", "95.4470198675497",
"18.3030303030303", "60.2739726027397", "0.158856235107228",
"98.7341772151899"), pourcentage = c(5.37796226165473, 4.55191916519208,
3.87140518282095, 2.79151300666457, 2.66748251170021, 2.50955034811226
), pourcentage_cumule = c(78.4062908267046, 82.9582099918967,
86.8296151747176, 89.6211281813822, 92.2886106930824, 94.7981610411947
)), row.names = c(NA, -6L), class = c("tabyl", "tbl_df", "tbl",
"data.frame"), core = structure(list(code_1 = c("M01b", "C01",
"C02", "C04", "M01", "C03", "M99", "C05", "O01", "C07", "C08",
"C99", "C98", "C10", "C06", "M03", "O02", "M02", "M04", "C01b",
"O03", "S99", "***", "C10b", "M05", "M98", "O04"), regroupement_elsan = c("Endoscopies
digestives",
"Ortho (+ rhumato et rachis)", "Chirurgie digestive", "Uro-néphro",
"Gastro", "Ophtalmo", "Divers médecine", "Gynéco", "Accouchements",
"bouche et dents", "Tissus mou et chir plastique", "Divers chir",
"Chir esth et hors sécu", "Chir thoracique et vasculaire", "ORL Stomato sf bouche et
dent",
"Pneumologie", "Obstétrique autre (hors IVG)", "Cardio Vasc (médecine)",
"Neurologie", "Rachis", "IVG", "Séances autres", "Autres", "Chir thoracique",
"Soins palliatifs", "Vasculaire interventionnel", "Néo nat"),
actes_2019 = c(36079, 29520, 14618, 6515, 9179, 5589, 6024,
4150, 4028, 3458, 2137, 2180, 575, 449, 866, 388, 294, 311,
714, 395, 292, 1842, 10, 0, 4, 0, 1), actes_2020 = c(30192,
25451, 12845, 7376, 7933, 4167, 3740, 2994, 3348, 2206, 2107,
1477, 575, 437, 337, 897, 193, 218, 267, 308, 118, 737, 8,
4, 0, 11, 5), actes_2021 = c(42333, 24055, 13735, 8196, 6504,
5505, 4682, 3376, 3226, 3035, 2571, 1134, 689, 511, 352,
272, 181, 161, 138, 106, 82, 61, 18, 8, 7, 0, 0), sejours_2019 = c(6992,
5493, 2577, 1221, 1631, 2502, 1028, 852, 1455, 1288, 540,
397, 236, 158, 260, 63, 148, 101, 90, 44, 246, 1820, 4, 0,
1, 0, 1), sejours_2020 = c(5811, 4946, 2220, 1220, 1335,
1819, 726, 574, 1371, 801, 554, 269, 221, 140, 94, 42, 109,
79, 58, 34, 98, 720, 2, 1, 0, 1, 5), sejours_2021 = c(7922,
5144, 2523, 1451, 1109, 2416, 825, 657, 1259, 1106, 649,
264, 278, 162, 111, 51, 108, 69, 30, 21, 77, 54, 7, 1, 2,
0, 0), tx_0_nuit_2019 = c("96.0955377574371", "63.5718186783179",
"41.4435389988359", "36.2817362817363", "3.92397302268547",
"90.7673860911271", "32.9766536964981", "57.5117370892019",
"0.206185567010309", "98.9130434782609", "72.5925925925926",
"53.904282115869", "13.9830508474576", "96.2025316455696",
"50.7692307692308", "42.8571428571429", "85.1351351351351",
"72.2772277227723", "11.1111111111111", "4.54545454545455",
"100,0", "100,0", "100,0", "0,0", "0,0", "0,0", "0,0"), tx_0_nuit_2020 =
c("96.0936155567028",
"67.3069146785281", "40.5855855855856", "34.344262295082",
"3.29588014981273", "92.9081913139087", "47.1074380165289",
"59.581881533101", "0.291757840991977", "99.250936329588",
"76.3537906137184", "49.814126394052", "11.7647058823529",
"99.2857142857143", "53.1914893617021", "16.6666666666667",
"74.3119266055046", "81.0126582278481", "25.8620689655172",
"8.82352941176471", "98.9795918367347", "100,0", "100,0",
"100,0", "0,0", "0,0", "20,0"), tx_0_nuit_2021 = c("96.7053774299419",
"73.2892690513219", "51.0503369005153", "41.9021364576154",
"3.6068530207394", "95.4470198675497", "18.3030303030303",
"60.2739726027397", "0.158856235107228", "98.7341772151899",
"83.9753466872111", "60.2272727272727", "50,0", "94.4444444444444",
"72.972972972973", "1.96078431372549", "81.4814814814815",
"85.5072463768116", "43.3333333333333", "52.3809523809524",
"100,0", "100,0", "100,0", "100,0", "0,0", "0,0", "0,0")), row.names = c(NA,
-27L), class = "data.frame"), tabyl_type = "two_way", totals = "row")
And the code I tried :
library(janitor)
autres %>%
adorn_totals("row")
Could anyone help ? I had indeed used the adorn_totals function on the dataframe used to generate the dataframe "autres", but I made sure the row "total" isn't in the dataframe "autres" anymore.
With the object you have shared as x:
x %>%
untabyl() %>%
adorn_totals()
Why it works:
You can see at the end of the object you shared, tabyl_type = "two_way", totals = "row". Those attributes are stored with the data.frame you're working with. When you try to adorn_totals() a second time, janitor checks this and errors.
When you call untabyl() it strips those attributes. Then adorn_totals() succeeds.
I notice you have a cumulative percentage column. If desired, you can control exactly which columns get a totals value in adorn_totals() - see ?adorn_totals and the ... argument for how, and here's an example: https://stackoverflow.com/a/69759313.

lost label inside the data when using Kable and for loop function

test1 <- structure(list(weight = c(0.2158, 0.799, 0.611, 0.4969, 0.3469,
1.0107, 0.6946, 0.9415, 1.4008, 0.6192), Q2_1 = structure(c(4,
4, 2, 2, 3, 3, 3, 2, 3, 2), label = "How worried, if at all, are you about each of the following? - You or someone in your family will get sick with COVID-19", format.spss = "F40.0", display_width = 5L, labels = c(Skipped = -1,
`Very worried` = 1, `Somewhat worried` = 2, `Not too worried` = 3,
`Not at all worried` = 4), class = c("haven_labelled", "vctrs_vctr",
"double")), Q2_2 = structure(c(3, 4, 2, 4, 3, 3, 4, 2, 3, 4), label = "How worried, if at all, are you about each of the following? - You might experience serious side effects from the COVID-19 vaccine", format.spss = "F40.0", display_width = 5L, labels = c(Skipped = -1,
`Very worried` = 1, `Somewhat worried` = 2, `Not too worried` = 3,
`Not at all worried` = 4), class = c("haven_labelled", "vctrs_vctr",
"double")), group = c("E", "E", "E", "D", "E", "E", "D", "E",
"D", "E")), row.names = c(NA, -10L), class = "data.frame")
I am using this data to create cross table and also with the question by using for loop
library(pollster)
library(rlang)
library(labelled)
library(haven)
crosstab(
df = test1,
x = Q2_1,
y = group,
weight = weight,
pct_type = "column")%>%
kable(caption = get_label(test1$Q2_1))
The dput() result is and correct after running the code
structure("<table>\n<caption>How worried, if at all, are you about each of the following? - You or someone in your family will get sick with COVID-19</caption>\n <thead>\n <tr>\n <th style=\"text-align:left;\"> Q2_1 </th>\n <th style=\"text-align:right;\"> D </th>\n <th style=\"text-align:right;\"> E </th>\n </tr>\n </thead>\n<tbody>\n <tr>\n <td style=\"text-align:left;\"> Somewhat worried </td>\n <td style=\"text-align:right;\"> 19.16831 </td>\n <td style=\"text-align:right;\"> 47.79164 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Not too worried </td>\n <td style=\"text-align:right;\"> 80.83169 </td>\n <td style=\"text-align:right;\"> 29.87610 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> Not at all worried </td>\n <td style=\"text-align:right;\"> 0.00000 </td>\n <td style=\"text-align:right;\"> 22.33225 </td>\n </tr>\n <tr>\n <td style=\"text-align:left;\"> n </td>\n <td style=\"text-align:right;\"> 2.59230 </td>\n <td style=\"text-align:right;\"> 4.54410 </td>\n </tr>\n</tbody>\n</table>", format = "html", class = "knitr_kable")
Now I am using for loop to build the table but somehow I lost the label in the data
library(pollster)
library(rlang)
library(labelled)
library(haven)
for (i in colnames(test1)[2:3]) {
table <- crosstab(
df = test1,
x = !!sym(i),
y = group,
weight = weight,
pct_type = "column")%>%
kable(caption = get_label(i))
print(table)
}
"How worried, if at all, are you about each of the following? - You or someone in your family will get sick with COVID-19" this sentence is missing. Does anyone know how to make it appear with forloop?

subtract the values in one dataframe by the mean created by summarise in dplyr

I have two dataframes, one is the original data:
df <- structure(list(day = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2), Subject = c(1, 1, 1, 1, 1, 1, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 12, 12, 12, 12,
12, 12, 13, 13, 13, 13, 13, 13, 17, 17, 17, 17, 17, 17), TimePoint = c(1,
5, 9, 13, 17, 21, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
1, 5, 9, 15, 17, 21, 1, 5, 9, 13, 17, 21, 1, 5, 9, 13, 17, 21,
1, 5, 9, 13, 17, 21), C4b = c(489.1, 3757.5, 4013.7, 963.4, 668.8,
2135.4, 1793.5, 2485.9, 1337.2, 1200.1, 1854.5, 1163.8, 1050.4,
1514.7, 1134, 1283.9, 1883.2, 1160, 441.4, 318.4, 261.8, 392,
380.9, 312, 1731.1, 1482.9, 1635.6, 1144.3, 1455.3, 1427.1, 1202.6,
1212.7, 1294.8, 1406.6, 2153.3, 1135, 1104.5, 1129.3, 737.4,
1010.9, 934.3, 704.2), `Coagulation Factor XI` = c(2149.4, 2055.8,
2256.3, 2179, 1859.5, 2158.4, 1877.4, 1800.7, 1838.7, 1899.9,
1867, 1827.9, 1818.7, 1847, 1807.7, 1737, 2394.9, 1726.2, 1756.3,
1746.3, 1744.5, 1573.8, 1765.5, 1954.1, 1522.4, 1387.7, 1374.4,
1357.3, 1433.3, 1386.5, 1575.7, 1531.8, 1560.9, 1810.4, 1657.2,
1509.4, 2110.4, 1974.5, 1856.1, 1939.6, 1832.3, 1932.5), CTACK = c(798.9,
857.5, 702.9, 707.6, 903.7, 749.9, 689.2, 734.1, 716.8, 645.2,
641.2, 663.1, 733.3, 667.3, 774.3, 782.2, 1766.7, 679.2, 1950.6,
2084.9, 2021.5, 1930.8, 1952.3, 1917.2, 723.9, 709.2, 670.7,
716.4, 944.9, 655.7, 706.8, 734.2, 680.5, 720.4, 778.3, 790.2,
962.5, 726.4, 761.9, 849.2, 701.1, 664.3), Endostatin = c(30563,
30006.5, 25972.2, 28048.9, 24503.9, 30371.2, 49733.9, 54933.8,
54293.3, 60007.4, 60403.9, 58870.4, 56801, 59752.6, 54336.3,
47746, 21270.4, 67312.9, 61931.5, 66395.3, 65680.8, 64419.4,
63415, 67230.7, 49444.2, 55122.2, 52333, 62328.7, 47513.9, 61530,
52549.8, 53633, 53983.7, 49023.8, 47305.6, 50569.8, 58754.1,
65727.9, 78382, 68290.8, 69386.8, 59982.4), `TIMP-1` = c(279.4,
262.4, 295.9, 273.3, 294.9, 278.3, 279.4, 238.7, 224.2, 239.3,
235.7, 251.7, 228.2, 237.3, 258.4, 262.4, 389.4, 237.8, 303.1,
296.4, 295.4, 297, 317, 351.6, 310.4, 244.2, 250.8, 261.1, 283.1,
251.4, 242.2, 223.3, 234.6, 291.2, 262.3, 249.7, 293.9, 259.4,
238.9, 257.9, 248.2, 329.3), tPA = c(377.9, 326.9, 346.3, 318.3,
314, 348.2, 291.2, 427.8, 433.1, 428.8, 370.9, 390, 354, 354.4,
368.8, 364.7, 595.2, 400.1, 354, 356.8, 368.7, 363.5, 394.3,
412.3, 319, 406.9, 415.4, 292.3, 320.9, 348.2, 532, 457.4, 417.3,
404, 401.5, 533.5, 213.6, 346.7, 310.7, 292.6, 280.2, 287.1),
`EG-VEGF` = c(106.8, 102.2, 107, 108.1, 138.8, 107.5, 88.1,
85.7, 82.7, 91.7, 98.8, 91.1, 82.3, 90.3, 89.2, 94.9, 128.3,
94.6, 529.1, 679.3, 599.4, 644.5, 674.1, 584.5, 98.2, 101.1,
97.3, 95.3, 86.8, 92.5, 101.9, 94.9, 109, 94.1, 103.8, 98.2,
92, 98.8, 91.6, 92.9, 98.8, 105.8), `TIMP-2` = c(466.5, 420.7,
479.8, 423, 462.7, 393.1, 400.5, 380.3, 355.9, 393.7, 423.6,
401.6, 364.2, 372.8, 391.3, 480.6, 1171.4, 357.8, 533.7,
522.6, 523.1, 511.5, 511, 644.8, 405.3, 398.2, 393, 369.7,
427.8, 380, 396.3, 394.5, 407, 490.9, 435.6, 402.7, 424.3,
436, 391.6, 405.6, 414.2, 536.2), `TGF-b1` = c(1451.2, 1194.6,
1521.3, 1705.8, 1945.4, 1900.2, 1839.4, 1701.9, 1752.9, 1714.6,
1597.6, 1660.5, 1786.9, 1694, 1519.6, 1906.1, 1654.2, 1636,
1566.8, 1730.9, 1496.2, 1850.9, 1715.1, 1648.8, 1834.9, 1686,
1769.4, 1750.8, 1833, 1862.6, 1511, 1505.9, 1524.9, 1514,
1391.2, 1369.1, 2064.6, 1790.9, 1799.1, 1548.2, 1839, 1667
), `VEGF sR3` = c(3094.3, 3235, 3116.3, 3027.1, 2536, 3061.8,
3215.7, 3189.6, 3139.1, 3618.8, 3585.6, 3556, 3326.7, 3167.5,
3403.3, 2583.1, 1621.6, 3415.2, 2293.9, 2508.4, 2662.6, 2486.2,
2538.8, 2452.5, 3012.5, 2920.1, 2914.1, 2870, 2455.2, 2809.3,
3534.8, 3501.9, 3691.4, 3517.6, 3414, 3405.6, 1943.3, 2334.2,
2137.4, 2185.7, 2273.2, 2304.9), C5 = c(5566.9, 5466.7, 5591.6,
5552.7, 5348.3, 5388.4, 5499.1, 5834.1, 5556.7, 5737.5, 5632.2,
5886.4, 5543.2, 6134.6, 5597.3, 5557.9, 5446.3, 5863.7, 5699.8,
5263.7, 5773.3, 5313.7, 6014.2, 5453.3, 6284.5, 5658.5, 5491.2,
5855.1, 5477.2, 5815.2, 5938.1, 5660.6, 6190.9, 5626.5, 6248.6,
5673, 6071.4, 6262.5, 5649.1, 6052, 6000.4, 5649), `Apo E` = c(3351.8,
936.5, 928.1, 3096.5, 2267.6, 2217.1, 2143.2, 2547.1, 2368.6,
2531.5, 1922.4, 2134.3, 2283.7, 2131, 2260.3, 2249.8, 2001.2,
2271.8, 3635.3, 2338.7, 2301.2, 2705, 2604.3, 2738.5, 5091.4,
3638.9, 2710.4, 3605, 3683, 3016.1, 3698.2, 3050.5, 2162.1,
2086.9, 2500.5, 2449.1, 4416, 2628.9, 2902.4, 3100.8, 2433.7,
3083.3), BDNF = c(325, 324, 337.9, 436.6, 557.3, 379.5, 556.2,
458.3, 400.3, 447.4, 448.1, 450.3, 425.1, 456.4, 482.1, 585,
663.2, 424.9, 343.8, 337.2, 328.1, 417.9, 343.2, 386.1, 590.6,
359.9, 340.3, 360.5, 394.1, 374.6, 367.9, 294.1, 319.4, 320,
366.2, 372.1, 502.1, 403.1, 432.9, 397.3, 389, 364.5), `bFGF-R` = c(12689.3,
13327.1, 12159.8, 11959.7, 11430.1, 11628.7, 11430.7, 12808.9,
11439, 12836.8, 13735.2, 12351.3, 11754, 12071.3, 11841.7,
10368.6, 12122.4, 12371.7, 11184.5, 11499.1, 11687.9, 10997.4,
11006.7, 10709.3, 11615, 12553.3, 11459.9, 12403, 10952,
12060.3, 13330.8, 12688.8, 13717.2, 11868.7, 11919.1, 11584.5,
10987.7, 12370.3, 11619.4, 11737.2, 12695.7, 12403.2), C8 = c(1868.7,
1678.4, 1916.9, 1966.6, 1724.9, 2028, 1840.3, 1797.4, 1871.4,
1967.9, 1926.4, 1860.2, 1860.4, 1901.4, 1951.1, 1675.4, 1026,
2024.3, 1950.6, 2174.5, 2266.5, 2251.5, 2176.4, 2067.2, 1968,
2187.1, 2360.5, 2057.5, 1971.1, 2202.2, 2099.5, 2337.2, 2320.8,
2232.9, 2358.2, 2374.8, 2071.3, 2773.3, 2695.9, 2641.2, 2738.7,
2607), `Cathepsin G` = c(1434.9, 1347, 1410.5, 1421.1, 2318.2,
1675, 1025.9, 1217.4, 1021.9, 1088.4, 1034.2, 1099.8, 1080.1,
1051.2, 967.8, 3874.4, 1875.6, 1058.9, 1093.7, 1083.2, 922.1,
1204.4, 1126.1, 1157.9, 1642.2, 1528.4, 1627.3, 1811.6, 1498.4,
1759.8, 926.3, 1022.4, 1106.7, 1058.7, 999.1, 995.3, 1020.5,
1085.4, 1088.9, 961.9, 1135.7, 1080.7), `CXCL16, soluble` = c(6878.8,
7479.3, 7088.7, 6739.4, 6143.9, 7477.5, 6742, 6822.4, 6164.9,
7320.9, 7459.1, 7150.5, 6407.1, 6504, 6901.8, 5929.6, 3924.1,
7827.3, 7358.7, 7758.3, 8305.5, 7586.9, 7829.1, 8268.3, 6860.7,
7470.7, 6857, 7003.7, 6364.7, 7738.7, 5441.6, 5609.3, 5732.5,
5128.2, 5642.7, 5402.4, 5170.2, 6272, 5963, 5996.4, 6461,
6721.3), `FGF-10` = c(255.2, 210, 262.6, 303.6, 219.4, 301.6,
241.2, 283.5, 248.6, 260.1, 265.7, 299.5, 268.9, 265.3, 201.3,
190.3, 296.6, 239.5, 242.7, 287.3, 216.2, 288.8, 283.8, 246.7,
255.1, 268.6, 236.3, 258.4, 206.8, 259.4, 264.1, 233.2, 277.1,
205.7, 200, 193.1, 251, 228, 229.9, 213.6, 247.2, 235.2),
`FGF-8B` = c(712.8, 648.4, 704.5, 763.9, 837.4, 795.9, 836.1,
841.7, 872.4, 860.1, 921.1, 845.8, 843.6, 875.2, 850, 847.4,
934.7, 938.6, 715.6, 823.9, 733.3, 801.1, 800.3, 819.9, 791.1,
930.8, 938.3, 869.6, 794.8, 939.9, 925.9, 971.2, 1015.9,
928.8, 851.9, 827, 833.6, 837.7, 858, 828.2, 935.7, 900.5
), GIIE = c(270, 254.6, 268.7, 279, 224.4, 293.2, 239.8,
238, 222.9, 260.2, 282.3, 262.3, 239, 241, 238.7, 200.6,
207.3, 252, 270.8, 281.1, 354.2, 289.2, 293, 295.2, 274.5,
291.4, 270.6, 275.8, 232, 272.7, 267, 245.3, 278.3, 260.6,
264, 250.6, 232.9, 274.4, 256.2, 254.1, 271.2, 282), GV = c(433.7,
441.1, 438.9, 468, 425.6, 459.2, 317.6, 332.2, 326, 306.4,
307.4, 310.6, 347.9, 317, 273.1, 325.9, 798.4, 299.1, 327.8,
307.9, 258.6, 308.7, 306.6, 298.6, 319.2, 326.2, 299.8, 329,
436.5, 297.7, 320.9, 306.6, 314.1, 312.1, 298.1, 300.1, 417,
306.6, 314.7, 321.4, 304.8, 305), `IL-12` = c(725.7, 667,
734.8, 772.8, 1045.1, 829.4, 659.4, 695.3, 653.8, 672.8,
701.1, 658.1, 683.5, 670.8, 678.8, 1002.5, 991.4, 703.8,
667.9, 714.1, 630.6, 720, 689.8, 781.4, 671.2, 715.2, 748.9,
693.2, 723.5, 724.7, 868.6, 891.2, 917.9, 858.8, 868.9, 828.6,
744.7, 711.9, 715.1, 683.2, 740.2, 724.3)), row.names = c(NA,
-42L), class = c("tbl_df", "tbl", "data.frame"))
My original data has an enormous amount of variables (1,130) of which I used the library(dplyr) summarise function to create mean values by TimePoint for each of the columns.
df_mean <- df %>%
group_by(TimePoint) %>%
summarise_at(vars(C4b:GV), mean, na.rm = T)
Now I want to create a new dataframe that is simply the difference between the original values in df and the mean of each time point for all the variables so essentially df - df_mean = new dataframe except for the variables "day", "Subject", and "TimePoint".
Thank you!
scale() function from R Base, with scale = FALSE for the centering option
mutate_at() to apply to multiple variables at once
vars() to select list of variables
! to select complement of variables - you don't want it applied to day and Subject
library(tidyverse)
df_centered <- df %>%
group_by(TimePoint) %>%
mutate_at(vars(!c("day", "Subject")), ~scale(., scale = FALSE), na.rm = TRUE)
I tried something like this, hope it helps.
df1 <- df[,-c(1,2,25)]
df_mm <- full_join(df1, df_mean, by = "TimePoint")
df_ss <- NULL
names <- colnames(df)[-length(df)]
for(i in 2:length(df1)){
df_ss[[i]] <- (df_mm[,i] - df_mm[,length(df1)+i-1])
}
df_ss[1] <- NULL
df_ss <- do.call(cbind, df_ss)
df_ss <- mutate(df_ss,
day = df$day,
Subject = df$Subject,
TimePoint = df$TimePoint)
df_ss <- df_ss[,c(22:24,1:21)]
colnames(df_ss) <- names
View(df_ss)

Correlation Matrix by group/category

I'm writing a code to calculate a portfolio's volatility for different clients in my company but I'm stuck in a process that will be explained below:
Sample:
dat <- structure(list(CNPJ = c(101425781, 101825381, 101824382, 101823383,
101343863, 101275931, 101733473, 101883323, 101730476, 101618588,
101585621, 101884322, 101617589, 101298908, 101853353, 101266940,
101569637, 101428778, 101260946, 101261945, 101567639, 101730476,
101618588, 101585621, 101884322, 101617589, 101298908, 101853353,
101266940, 101267939, 101628578, 101440766, 101435771, 101434772,
101527679, 101438768, 101266940, 101266940, 101824382, 101823383,
101343863, 101275931, 101733473, 101475731, 101233973, 101258948,
101311895, 101274932, 101865341, 101692514, 101284922, 101357849,
101694512, 101649557, 101384822, 101625581, 101325881, 101404802,
101638568, 101773433, 101301905, 101637569, 101698508, 101558648,
101762444, 101772434, 101770436, 101761445, 101771435, 101302904,
101755451, 101762444, 101772434, 101770436, 101585621, 101884322,
101617589, 101762444, 101462744, 101544662, 101334872, 101744462,
101538668, 101521685, 101465741, 101323883, 101683523, 101682524,
101820386, 101737469, 101742464, 101728478, 101489717, 101764442,
101606600, 101679527, 101607599, 101493713, 101504702, 101694512,
101649557, 101384822, 101625581, 101325881, 101404802, 101619587,
101811395, 101677529, 101664542, 101729477, 101665541, 101663543,
101622584, 101559647, 101794412, 101780426, 101825381, 101824382,
101823383, 101343863, 101275931, 101733473, 101883323, 101730476,
101794412, 101780426, 101730476, 101665541, 101663543, 101730476
), NOME_CLIENTE = c("André", "André", "André", "André", "André",
"André", "André", "Leandro", "Leandro", "Leandro", "Leandro",
"Leandro", "Leandro", "Leandro", "Leandro", "Leandro", "Thomaz",
"Thomaz", "Thomaz", "Thomaz", "Thomaz", "Thomaz", "Thomaz", "Thomaz",
"Thomaz", "Thomaz", "Thomaz", "Camile", "Camile", "Camile", "Camile",
"Camile", "Lucia", "Lucia", "Lucia", "Lucia", "Lucia", "Lucia",
"Lucia", "Lucia", "Lucia", "Lucia", "Lucia", "Lucia", "Lucia",
"Tadeu", "Tadeu", "Tadeu", "Tadeu", "Tadeu", "Tadeu", "Tadeu",
"Tadeu", "Tadeu", "Tadeu", "Tadeu", "Lucas", "Lucas", "Lucas",
"Lucas", "Lucas", "Ana", "Ana", "Ana", "Fred", "Fred", "Fred",
"Fred", "Fred", "Vania", "Vania", "Vania", "Vania", "Vania",
"Rogerio", "Rogerio", "Rogerio", "Murilo", "Alex", "Alex", "Alex",
"Alex", "Alex", "Alex", "Alex", "Adriano", "Adriano", "Adriano",
"Adriano", "Adriano", "Adriano", "Laura", "Laura", "Laura", "Laura",
"Laura", "Laura", "Laura", "Laura", "Marina", "Marina", "Marina",
"Marina", "Marina", "Josi", "Josi", "Josi", "Josi", "Josi", "Oscar",
"Oscar", "Oscar", "Oscar", "Oscar", "Matheus", "Matheus", "Matheus",
"Matheus", "Matheus", "Matheus", "Carla", "Carla", "Vicente",
"Vicente", "Vicente", "Vicente", "Vicente", "Vicente", "Vicente",
"Vicente"), `Retorno do fechamento em 1 dia (de 05Jul21 até 06Jul21) Em moeda orig ajust p/ prov` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.00778361427364871, 0.0189589731235174, 0.0167292435435229,
0.0209282798095956, 0.0175226514329552, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.178722146574728,
-0.179207335986575, 0, 0, 0, 0, 0, 0, 0, 0, -0.178722146574728,
-0.179207335986575, 0, 0, 0, 0), `Retorno do fechamento em 1 dia (de 02Jul21 até 05Jul21) Em moeda orig ajust p/ prov` = c(0.942365785340371,
0.805477017638623, 0.802614427993831, 0.79957278976508, 0.343775841429306,
0.770676273714344, 0.681504154090362, 0.36820554996666, 0.675119873812946,
0.886332713707816, -0.196678715019516, 0.368162580161879, 0.0573179420825909,
0.630863469814358, 0.0537324149263441, 0.053517096239375, 0.053270060561772,
0.123570029245457, 0.00240310728258919, 0.000954475581238512,
0.012390517804306, 0.675119873812946, 0.886332713707816, -0.196678715019516,
0.368162580161879, 0.0573179420825909, 0.630863469814358, 0.0537324149263441,
0.053517096239375, -0.175190593472507, 0.0513788099851809, 0.0571791188122006,
-0.000460241699329345, -0.0055272630561376, -0.180391395588231,
-0.000360705416824203, 0.053517096239375, 0.053517096239375,
0.802614427993831, 0.79957278976508, 0.343775841429306, 0.770676273714344,
0.681504154090362, -0.00212285012821667, 0.0140633886985597,
0.0159728740982246, 0.0153047161802533, 0.0171541991221602, 0.0161614329044824,
0.0239725273786462, 0.0170795990925399, 0.0146915856021224, 0.0208990009923582,
0.0251777479206794, 0.0101244871984818, 0.083773042933899, 0.00613068441452924,
0.0596999600020354, -0.000258351337834029, -0.0318828113449854,
0.508815288958431, -0.0037543713915511, -0.0422787105890166,
-0.00410938619097578, 0.0156755046191392, -0.0350934983543993,
-0.0351224380210624, 0.0150984966239776, -0.0352719532202173,
0.510709844456869, 0.0136689604914864, 0.0156755046191392, -0.0350934983543993,
-0.0351224380210624, -0.196678715019516, 0.368162580161879, 0.0573179420825909,
0.0156755046191392, -0.239597912332101, -0.152928001898545, -0.0235288461226446,
-0.198399838154728, -0.462776459698944, -0.0380991642487061,
-0.466886323647486, 0.00119402775453636, 0.14253430399549, 0.139307505560282,
0.102990215236787, -0.218033586497768, -0.218882237186335, -0.0285126700873661,
-0.0373568835129845, 0.0905571250768844, 0.0210312804483692,
-0.0707320114997856, 0.0156884318130324, -0.351507907998894,
-0.0933908677325235, 0.0208990009923582, 0.0251777479206794,
0.0101244871984818, 0.083773042933899, 0.00613068441452924, 0.0596999600020354,
-0.229178049994516, -0.0865143876580987, -0.10620687098708, -0.0552723868167959,
-0.0814444899333466, -0.0519984678248875, -0.0520159507686913,
-0.117729024987057, -0.0530218498170143, 0.158825809739938, 0.158491499496449,
0.805477017638623, 0.802614427993831, 0.79957278976508, 0.343775841429306,
0.770676273714344, 0.681504154090362, 0.36820554996666, 0.675119873812946,
0.158825809739938, 0.158491499496449, 0.675119873812946, -0.0519984678248875,
-0.0520159507686913, 0.675119873812946), `Retorno do fechamento em 1 dia (de 01Jul21 até 02Jul21) Em moeda orig ajust p/ prov` = c(0.979534778889501,
1.00895916129957, 1.00597755536, 1.00293131490616, 1.19184508603212,
0.892244829992705, 1.06031548002647, -0.242739015629923, 1.05267639410158,
1.12581394059816, -1.26531522691948, -0.242730580339412, 0.829333663568832,
0.709356947118067, -0.168167339415959, -0.167775623322086, -0.167328415955126,
0.329745306589757, 0.27122778701596, 0.268143224639061, -0.124702736684412,
1.05267639410158, 1.12581394059816, -1.26531522691948, -0.242730580339412,
0.829333663568832, 0.709356947118067, -0.168167339415959, -0.167775623322086,
-0.0913384802515793, -0.11147755831189, 0.0987762688964722, 0.0772892448367202,
0.0721167476513074, 0.0718083483661758, 0.13765686780971, -0.167775623322086,
-0.167775623322086, 1.00597755536, 1.00293131490616, 1.19184508603212,
0.892244829992705, 1.06031548002647, -0.0107362609924166, 0.108200344766374,
0.0167877662534011, 0.0166125437317532, 0.019362857528904, 0.0170939973031636,
0.0149137784319464, 0.0175510795088485, 0.0219936013309052, 0.0153708668221952,
0.0214045179745881, 0.218257983397052, 1.93124338729831, 0.0966225481533911,
0.0660155585137545, 0.160651210353535, 0.281960610300303, 0.168294318973494,
0.156532869732473, 0.0235352978052106, 0.15597043420712, 0.178403708923724,
0.313215353344276, 0.313077565988351, 0.150220916111721, 0.313011823345732,
0.167659097860451, 0.148871797682659, 0.178403708923724, 0.313215353344276,
0.313077565988351, -1.26531522691948, -0.242730580339412, 0.829333663568832,
0.178403708923724, 0.118057045074238, 0.057461309734208, 0.444099056039704,
0.0440074078142061, 0.628042917742277, 1.91767980722943, 0.636043804843212,
0.22732198212907, 0.648415319665219, 0.631001178953738, 1.45504575739324,
0.0488470226628124, 0.0490176256789709, 0.420476676117687, 0.445707477410906,
0.528412471248885, 0.0766849934734637, 0.135209854306595, 0.094540198915638,
0.270248285050911, 0.480813477770425, 0.0153708668221952, 0.0214045179745881,
0.218257983397052, 1.93124338729831, 0.0966225481533911, 0.0660155585137545,
0.802627007942647, 0.363892160748946, 1.48838756485929, 0.340247581152653,
0.470643488733913, 0.330754261813127, 0.331557817662542, 0.245268716025748,
0.328566240204964, -0.0858315926052455, -0.0862059820974537,
1.00895916129957, 1.00597755536, 1.00293131490616, 1.19184508603212,
0.892244829992705, 1.06031548002647, -0.242739015629923, 1.05267639410158,
-0.0858315926052455, -0.0862059820974537, 1.05267639410158, 0.330754261813127,
0.331557817662542, 1.05267639410158), `Retorno do fechamento em 1 dia (de 30Jun21 até 01Jul21) Em moeda orig ajust p/ prov` = c(1.43870652973419,
1.41092075518827, 1.40891626124358, 1.40683828485635, 1.29712666603155,
1.28780756476772, 1.16027819913143, 1.15619966982194, 1.15166121959192,
1.12679697540443, 1.11872740271792, 1.09681450958306, 0.267671114488621,
0.222820941417012, 0.222602060603094, 0.22248505429161, 0.221691197657492,
0.220383319538087, 0.214968588261399, 0.211758096520498, 0.194644135626731,
1.15166121959192, 1.12679697540443, 1.11872740271792, 1.09681450958306,
0.267671114488621, 0.222820941417012, 0.222602060603094, 0.22248505429161,
0.1451038322557, 0.139518178730214, 0.13257357859402, 0.130725836606871,
0.125449788902188, 0.124899058755545, 0.12112907224946, 0.22248505429161,
0.22248505429161, 1.40891626124358, 1.40683828485635, 1.29712666603155,
1.28780756476772, 1.16027819913143, 0.0179505830601556, 0.0179249640495982,
0.0178968244654243, 0.0172540911080432, 0.0172192943864502, 0.0170852243172703,
0.0170261320818099, 0.0169619641383179, 0.0169404602274881, 0.0168244730957667,
0.016709737428755, -0.0211857909562241, -0.0216967600863427,
-0.0229697961913189, -0.0257060649346386, -0.0259964172983018,
-0.0275145673185762, -0.0289907728074468, -0.0292650344817957,
-0.0294223166747543, -0.0296824166980514, -0.030167581007845,
-0.0302402934721613, -0.0302878822367347, -0.03037016322196,
-0.030424068972934, -0.0310724994960765, -0.0318300612889288,
-0.030167581007845, -0.0302402934721613, -0.0302878822367347,
1.11872740271792, 1.09681450958306, 0.267671114488621, -0.030167581007845,
-0.0853457778248412, -0.0859374341416697, -0.0859406153722375,
-0.0865554517076816, -0.0882744773662125, -0.0887361663444608,
-0.0893140918378776, -0.0901054414498503, -0.0906405015484779,
-0.0920847652196244, -0.0937861297643394, -0.0947105819250282,
-0.0953150254645152, -0.110822802071198, -0.113156839324802,
-0.115255077889742, -0.12083339088349, -0.122396185088292, -0.124390845849121,
-0.130054255532741, -0.131201397198311, 0.0168244730957667, 0.016709737428755,
-0.0211857909562241, -0.0216967600863427, -0.0229697961913189,
-0.0257060649346386, -0.177713267203217, -0.179625764030789,
-0.181550171964773, -0.184798425652843, -0.186204287638247, -0.186833808493247,
-0.187116816960042, -0.18726764656094, -0.187312098569237, -0.188992797757237,
-0.189383511951746, 1.41092075518827, 1.40891626124358, 1.40683828485635,
1.29712666603155, 1.28780756476772, 1.16027819913143, 1.15619966982194,
1.15166121959192, -0.188992797757237, -0.189383511951746, 1.15166121959192,
-0.186833808493247, -0.187116816960042, 1.15166121959192), `Retorno do fechamento em 1 dia (de 29Jun21 até 30Jun21) Em moeda orig ajust p/ prov` = c(0.502124611193722,
1.08873834833503, 1.0863304585655, 1.08408597388916, 1.19717331272113,
0.643037106601696, 0.985535115250968, 1.25571238968405, 0.97833804320544,
0.539720013330225, -0.0171822072843497, 1.25885415855009, -0.297552030588122,
-0.526261176401022, 0.035477040000842, 0.0353613204424619, 0.0351307737219031,
0.0288115119474242, 0.189729943122074, 0.186261452654435, 0.0205766682483954,
0.97833804320544, 0.539720013330225, -0.0171822072843497, 1.25885415855009,
-0.297552030588122, -0.526261176401022, 0.035477040000842, 0.0353613204424619,
-0.11735292891899, 0.0925877280678833, 0.177379815249878, -0.136864399428305,
-0.141660541066813, -0.140943691440043, -0.0966895738201856,
0.0353613204424619, 0.0353613204424619, 1.0863304585655, 1.08408597388916,
1.19717331272113, 0.643037106601696, 0.985535115250968, -0.0017996449059865,
0.0312044658130617, 0.0138932151457993, 0.0152530168634257, 0.0200221114937449,
0.0161169335115119, 0.0274898708084947, 0.0186181776371086, 0.0182820524059935,
0.0239859622524818, 0.0205424532396137, 0.0759944194214768, -0.509912122015521,
0.00486758381157415, 0.0288131310298922, 0.00580397354497109,
-0.046727934932278, 0.153513796249172, 0.00224317063839408, -0.0344225619301142,
0.00192268780665472, 0.0188015475941938, -0.0515577000442136,
-0.0516044370669988, -0.00575247213419061, -0.051770751906588,
0.152701738261385, -0.00723539169484866, 0.0188015475941938,
-0.0515577000442136, -0.0516044370669988, -0.0171822072843497,
1.25885415855009, -0.297552030588122, 0.0188015475941938, -0.000709731102688238,
-0.125828953150631, -0.0583621415898961, -0.230176390323322,
0.0246811907345545, -0.286447172857152, 0.0252581143286079, -0.000968543736235006,
-0.00327709612975013, -0.000393667869502679, -0.233207584187767,
-0.25298826967628, -0.254608426985214, -0.112315356545878, -0.0684287759213476,
0.0235757685004501, -0.288741029726225, -0.101063827332837, -0.349614209790161,
-0.127183163567679, -0.119651697877998, 0.0239859622524818, 0.0205424532396137,
0.0759944194214768, -0.509912122015521, 0.00486758381157415,
0.0288131310298922, -0.179443232809717, -0.0405482861424389,
-0.336684563626477, 0.0314099312163307, -0.122985923007946, 0.028760595159838,
0.0289238596451469, 0.00404918064305093, 0.0272430881523178,
0.111774820288701, 0.11133259122289, 1.08873834833503, 1.0863304585655,
1.08408597388916, 1.19717331272113, 0.643037106601696, 0.985535115250968,
1.25571238968405, 0.97833804320544, 0.111774820288701, 0.11133259122289,
0.97833804320544, 0.028760595159838, 0.0289238596451469, 0.97833804320544
), `Retorno do fechamento em 1 dia (de 28Jun21 até 29Jun21) Em moeda orig ajust p/ prov` = c(-0.198023707343964,
0.165073225434753, 0.162118304069736, 0.159184927360911, 0.31501187786489,
0.480946872812638, 0.100753906190221, -0.0653304397019383, 0.0962356276431819,
-0.0881336358361295, -0.0533254209585721, -0.0677359893415996,
-0.204503703935188, 0.0372313692423631, 0.19837873915094, 0.198078832727333,
0.197325568842643, -0.322720231088169, 0.208725442644209, 0.205065749287314,
0.167832192164497, 0.0962356276431819, -0.0881336358361295, -0.0533254209585721,
-0.0677359893415996, -0.204503703935188, 0.0372313692423631,
0.19837873915094, 0.198078832727333, 0.0620278860878898, 0.0595328980125487,
-0.00318802449328359, 0.172116678731982, 0.166721905588929, 0.166025866019481,
0.0555906986846821, 0.198078832727333, 0.198078832727333, 0.162118304069736,
0.159184927360911, 0.31501187786489, 0.480946872812638, 0.100753906190221,
0.0145019028423121, 0.0341210115948343, 0.0196030874576536, 0.0151630909385858,
0.0171717618286493, 0.0166905201695045, 0.0386720310416422, 0.0170905304912594,
0.0321437632010202, 0.0290415791823762, 0.0290159981886973, 0.0224570892896736,
0.0550586113604368, 0.00599850245635025, 0.0569822685065446,
0.00715276200935477, 0.0707630950273597, 0.0603664986556396,
0.00360865669790655, 0.0138247363793198, 0.00322926134685986,
0.00569701842323411, 0.0788849310993101, 0.0787162032793276,
0.023551956837764, 0.0786520142355585, 0.0588474418691476, 0.0220792353502475,
0.00569701842323411, 0.0788849310993101, 0.0787162032793276,
-0.0533254209585721, -0.0677359893415996, -0.204503703935188,
0.00569701842323411, -0.288288556748739, 0.0193903986655641,
0.0118731610200484, -0.0138466287353367, -0.680894528341014,
-0.325431222609041, -0.695109194475663, 0.000547890522284433,
0.178201925700705, 0.17427996663173, 0.215817989919742, -0.0149371458064707,
-0.0149838482684572, -0.0245679943873256, 0.0144083751365542,
0.0886160698428284, 0.202712868485833, -0.0466606414192938, 0.218713049616781,
-0.862754137233424, 0.035604577169579, 0.0290415791823762, 0.0290159981886973,
0.0224570892896736, 0.0550586113604368, 0.00599850245635025,
0.0569822685065446, -0.195995577814756, 0.0630952594292467, 0.0203639445317094,
0.00807336509751622, 0.0235056655583321, 0.00701949902577326,
0.00712929831934161, -0.057338921851624, 0.00565966965950793,
0.271263730610372, 0.270847501633398, 0.165073225434753, 0.162118304069736,
0.159184927360911, 0.31501187786489, 0.480946872812638, 0.100753906190221,
-0.0653304397019383, 0.0962356276431819, 0.271263730610372, 0.270847501633398,
0.0962356276431819, 0.00701949902577326, 0.00712929831934161,
0.0962356276431819), `Retorno do fechamento em 1 dia (de 25Jun21 até 28Jun21) Em moeda orig ajust p/ prov` = c(-0.04575570274028,
-0.324605952846468, -0.327796321016649, -0.33096953857239, 0.310205801906704,
-0.414644634292927, -0.101955446643842, -0.792592311699991, -0.105553570938355,
-0.426584116303275, 0.384709813624795, -0.793544384760025, 0.244644467056787,
-0.113642475389497, -0.200582809884509, -0.200281002162228, -0.199668641380413,
0.105843198252842, 0.05128885331942, 0.0487525394419208, -0.144266975257779,
-0.105553570938355, -0.426584116303275, 0.384709813624795, -0.793544384760025,
0.244644467056787, -0.113642475389497, -0.200582809884509, -0.200281002162228,
-0.0204055452741159, 0.00692895773681812, -0.107229976947565,
-0.021897017268202, -0.026910665746982, -0.0267514958977699,
-0.0226308975470602, -0.200281002162228, -0.200281002162228,
-0.327796321016649, -0.33096953857239, 0.310205801906704, -0.414644634292927,
-0.101955446643842, 0.00656187421554932, 0.0711173595846049,
0.016080117529782, 0.0149099576447043, 0.0224479716052883, 0.0160585161211202,
0.0291353537249961, 0.0191598079254618, 0.0344285706887604, 0.0277284529147437,
0.0324757711496204, 0.255325436228304, 0.491043761394394, -0.007351639578701,
0.239665514345688, 0.0254665781540098, 0.246601338403707, 0.306360405738815,
0.021799597197969, 0.0359414310878492, 0.0214967376450659, 0.2530865072913,
0.273972895593033, 0.273773812295985, 0.216667755375965, 0.273744292098854,
0.306647065735888, 0.215286427555839, 0.2530865072913, 0.273972895593033,
0.273773812295985, 0.384709813624795, -0.793544384760025, 0.244644467056787,
0.2530865072913, -0.111104031839204, 0.157537165796384, 0.192098881598213,
0.0864217152411584, -0.0945294063967594, 0.521661975290044, -0.0958257593993039,
-0.0476185044135491, 0.42623207118595, 0.405392333959753, 0.856841270979203,
0.0956091435000417, 0.0959779299591901, 0.237147073858068, 0.219546595326392,
0.196438972307078, -0.0241040951550531, 0.163301830616547, -0.000792533046478638,
-0.264652587702585, 0.312989899975946, 0.0277284529147437, 0.0324757711496204,
0.255325436228304, 0.491043761394394, -0.007351639578701, 0.239665514345688,
0.428198364716081, 0.0950000918237492, 0.60943404041609, 0.238058063587232,
0.161433682296774, 0.221308266009146, 0.222009271055867, 0.0339463511409122,
0.219266381827765, -0.0260104882727319, -0.0264767391854548,
-0.324605952846468, -0.327796321016649, -0.33096953857239, 0.310205801906704,
-0.414644634292927, -0.101955446643842, -0.792592311699991, -0.105553570938355,
-0.0260104882727319, -0.0264767391854548, -0.105553570938355,
0.221308266009146, 0.222009271055867, -0.105553570938355), `Retorno do fechamento em 1 dia (de 24Jun21 até 25Jun21) Em moeda orig ajust p/ prov` = c(1.31500839142973,
1.2538675655378, 1.2512416806203, 1.2483983013226, 0.923949156276649,
1.53366348040436, 1.07913114661642, 0.981676446463098, 1.06919162481063,
1.00356835209823, 0.0938292467253632, 0.981684204998601, 0.0335199194523739,
-0.160056370532402, 0.625390207096643, 0.624604057702527, 0.622362618378247,
0.361656406130351, -0.212902135081094, -0.213394554157276, 0.499070715704875,
1.06919162481063, 1.00356835209823, 0.0938292467253632, 0.981684204998601,
0.0335199194523739, -0.160056370532402, 0.625390207096643, 0.624604057702527,
-0.0216325648580096, 0.212004635613994, 0.0234427629038692, 0.270697217638372,
0.264927992066077, 0.264052262537007, 0.0876192654686747, 0.624604057702527,
0.624604057702527, 1.2512416806203, 1.2483983013226, 0.923949156276649,
1.53366348040436, 1.07913114661642, 0.0221270523979911, 0.0283598365058424,
0.0168144269991899, 0.0146372844028519, 0.0276347756880568, 0.0168952665262623,
0.0280305044725537, 0.0247853928158293, 0.0215260746699641, 0.0224150851863669,
0.0331112487401697, -0.11593472909226, -1.49322215711436, -0.0149391249578912,
0.0804914230684517, 0.118418995771208, -0.245298802747129, -0.184812617681018,
0.114302423753543, -0.0609414437349187, 0.114008090167772, 0.109802194674558,
-0.27181676514374, -0.271866577804758, 0.0921201453820686, -0.27202933197259,
-0.188102052743488, 0.0906900539121125, 0.109802194674558, -0.27181676514374,
-0.271866577804758, 0.0938292467253632, 0.981684204998601, 0.0335199194523739,
0.109802194674558, -0.228354444789147, 0.00782648858148605, -0.175804663012968,
-0.248384703172633, -0.95458747309749, -1.45392726271893, -0.968984441897192,
-0.0592346845223801, -0.0362318211045931, -0.0311027364659822,
-0.835893042494718, -0.274180758242437, -0.275284712279245, -0.219692738210142,
0.115211368756718, -0.222768642652227, -0.06096580209487, -0.155160100985086,
-0.104768661731214, 0.11422998886701, 0.109853295543871, 0.0224150851863669,
0.0331112487401697, -0.11593472909226, -1.49322215711436, -0.0149391249578912,
0.0804914230684517, -0.695003834425734, -0.208113736607629, -1.01258187478379,
-0.00637666562397499, -0.255406660107838, -0.00643533894617576,
-0.00635902624708251, 0.00232062830036739, -0.00783108380346675,
0.157384331396315, 0.156946501556376, 1.2538675655378, 1.2512416806203,
1.2483983013226, 0.923949156276649, 1.53366348040436, 1.07913114661642,
0.981676446463098, 1.06919162481063, 0.157384331396315, 0.156946501556376,
1.06919162481063, -0.00643533894617576, -0.00635902624708251,
1.06919162481063)), row.names = c(NA, -130L), class = c("tbl_df",
"tbl", "data.frame"))
Labels:
"CNPJ" = Fund/Stock ID,
"NOME_CLIENTE" = Client Name,
Other columns = Return in Day, Return in Day-1, Return D-2,... Return D-n for a Year or aprox 260 days)
What I need to do is calculate the correlation matrix of the Funds for each unique NOME_CLIENTE. So the code needs to give me as output a list of matrices or something like that.
So, for Client "Andre" -> Corr Matrix of his 7 funds;
Client "Leandro" -> Corr Matrix of his 10 funds
and so on...
I need it this way because after that I will need to multiply a value by every client matrix to get the portfolio volatility.
For more information about Portfolio Volatility:
https://financetrain.com/analytical-approach-to-calculating-var-variance-covariance-method/
This will give you a list of matrices, one for each client:
library(RiskPortfolios)
library(tibble)
dat_clean <- tibble::as.tibble(dat)
names(dat_clean)[3:10] <- paste0('day', 8:1)
accounts <- unique(dat_clean$CNPJ)
clients <- unique(dat_clean$NOME_CLIENTE)
lcorrelations <- vector(mode = "list", length = length(clients)) # list of correlations
names(lcorrelations) <- clients
for(i in clients) {
returns_account_i <- t(as.matrix(dat_clean[dat_clean$NOME_CLIENTE == i, c(3:8)]))
lcorrelations[[i]] <- RiskPortfolios::covEstimation(returns_account_i)
}
# correlation matrix for André
> print(lcorrelations$André)
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 0.3940826 0.3110904 0.3108791 0.3106319 0.2485066 0.2383790 0.2778012
[2,] 0.3110904 0.3052529 0.3049751 0.3046908 0.2842727 0.2151196 0.2735981
[3,] 0.3108791 0.3049751 0.3046987 0.3044156 0.2839959 0.2148306 0.2733327
[4,] 0.3106319 0.3046908 0.3044156 0.3041340 0.2837319 0.2145246 0.2730624
[5,] 0.2485066 0.2842727 0.2839959 0.2837319 0.3214527 0.1938825 0.2652854
[6,] 0.2383790 0.2151196 0.2148306 0.2145246 0.1938825 0.1852168 0.1878199
[7,] 0.2778012 0.2735981 0.2733327 0.2730624 0.2652854 0.1878199 0.2530376

Binding COllection to Gridview

List<Person> pList = new List<Person>();
pList.Add(new Person(1, "John", "", "Shields", 29, 'M'));
pList.Add(new Person(2, "Mary", "Matthew", "Jacobs", 35, 'F'));
pList.Add(new Person(3, "Amber", "Carl", "Agar", 25, 'M'));
pList.Add(new Person(4, "Kathy", "", "Berry", 21, 'F'));
pList.Add(new Person(5, "Lena", "Ashco", "Bilton", 33, 'F'));
pList.Add(new Person(6, "Susanne", "", "Buck", 45, 'F'));
pList.Add(new Person(7, "Jim", "", "Brown", 38, 'M'));
pList.Add(new Person(8, "Jane", "G", "Hooks", 32, 'F'));
pList.Add(new Person(9, "Robert", "", "", 31, 'M'));
pList.Add(new Person(10, "Cindy", "Preston", "Fox", 25, 'F'));
pList.Add(new Person(11, "Gina", "`enter code here`", "Austin", 27, 'F'));
pList.Add(new Person(12, "Joel", "David", "Benson", 33, 'M'));
pList.Add(new Person(13, "George", "R", "Douglas", 55, 'M'));
pList.Add(new Person(14, "Richard", "", "Banks", 22, 'M'));
pList.Add(new Person(15, "Mary", "C", "Shaw", 39, 'F'));
gv1.DataSource = pList;
gv1.DataBind();
I want to display selected fields in the gridview. How to use EVAL function with it? ALso How to use DataField Property with it?
Hi you can use ItemTemplate as like
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Eval("Name")%>
<br/>
<%# Eval("Age")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
or see following link :
http://www.dotnetspider.com/resources/29877-Binding-Gridview-generic-list.aspx

Resources