structure

Filter values from list in R

偶尔善良 提交于 2019-12-03 11:59:41
I want to calculate the mean of a list of named numbers. There are numeric(0) values that I first want to remove. Also, I would like to retrieve which elements of the list contain numeric(0) values. Here is an example how the values could look like: >r["gg",] $`01_1_er` gg 0.5176445 $`02_1_er` gg 0.4990959 $`03_1_er` gg 0.5691489 $`22_1_er` numeric(0) $`23_1_er` numeric(0) $`25_1_er` gg 0.386304 And here is the result of str: > str(r["gg",]) List of 6 $ 01_1_er: Named num 0.518 ..- attr(*, "names")= chr "gg" $ 02_1_er: Named num 0.499 ..- attr(*, "names")= chr "gg" $ 03_1_er: Named num 0.569 .

Coldfusion - How to loop through an Array of Structure and print out dynamically all KEY values?

本小妞迷上赌 提交于 2019-12-03 11:40:06
Giving the Array of Structure below: I am able to print out all values from all fields by doing: <cfset ColumnNames = structKeyArray(ApiData[1])> <cfset ColumnLength = ArrayLen(ColumnNames)> <cfloop from="1" to="#ArrayLen(ApiData)#" index="i"> <cfdump var="#ApiData[i].Created#"> <cfdump var="#ApiData[i].Name#"> ...and so on Now I am trying to loop through all fields so that I dont have to actually write the name of each field. How do I do this dynamically? Something like: <cfloop from="1" to="#ArrayLen(ApiData)#" index="i"> <cfloop from="1" to="#ColumnLength#" index="i"> <!---<cfdump var="

nested structures and pointers

落爺英雄遲暮 提交于 2019-12-03 08:56:09
I dork this up just about every time I jump back into a C project. I'm getting a segfault when attempting to access a structure within a structure. Let's say I have the following (simplified) structures for a game: struct vector { float x; float y; }; struct ship { struct vector *position; }; struct game { struct ship *ship; } game; And a function to initialize the ship: static void create_ship(struct ship *ship) { ship = malloc(sizeof(struct ship)); ship->position = malloc(sizeof(struct vector)); ship->position->x = 10.0; } Then down in main(): int main() { create_ship(game.ship); printf("%f

C - Find the size of structure

淺唱寂寞╮ 提交于 2019-12-03 08:53:42
I was asked this as interview question. Couldn't answer. Write a C program to find size of structure without using the sizeof operator. struct XYZ{ int x; float y; char z; }; int main(){ struct XYZ arr[2]; int sz = (char*)&arr[1] - (char*)&arr[0]; printf("%d",sz); return 0; } Here's another approach. It also isn't completely defined but will still work on most systems. typedef struct{ // stuff } mystruct; int main(){ mystruct x; mystruct *p = &x; int size = (char*)(p + 1) - (char*)p; printf("Size = %d\n",size); return 0; } Here's two macro versions for the two forms of sizeof (takes a type vs.

How to fill a DataTable with a List(Of t) or convert a List(Of t) to a DataTable?

元气小坏坏 提交于 2019-12-03 07:35:54
I have read many posts on this topic; among them and most recently .NET - Convert Generic Collection to Data Table . Unfortunately, all to no avail. I have a generic collection of structures : Private Structure MyStruct Dim sState as String Dim lValue as Long Dim iLayer as Integer End Structure Dim LOStates As New List(Of MyStruct) I need to fill a DataTable with this list of structures but have no idea how to go about doing this. I am using vb.net in Visual Studio 2008. Any insights will be greatly appreciated The code you linked assumes the members are declared as properties. You didn't

How do I load example datasets in R?

喜夏-厌秋 提交于 2019-12-03 07:34:57
问题 Let's say I want to reproduce an example posted on StackOverflow. Some have suggested posters use dput() to help streamline this process or one of the datasets available in the base package. In this case, however, suppose I have only been given the output of the dataframe: > site.data site year peak 1 ALBEN 5 101529.6 2 ALBEN 10 117483.4 3 ALBEN 20 132960.9 8 ALDER 5 6561.3 9 ALDER 10 7897.1 10 ALDER 20 9208.1 15 AMERI 5 43656.5 16 AMERI 10 51475.3 17 AMERI 20 58854.4 Do I have other options

Lock free & Thread-Safe IList<T> for .NET

纵然是瞬间 提交于 2019-12-03 07:20:34
问题 Is there a lock-free & thread-safe data structure that implements IList? Naturally by lock-free I mean an implementation that makes no use of locking primitives in .NET but rather uses interlocked operations / atomic operations to achieve thread safety... There isn't one, apparently under the concurrent data structures... Has anyone seen one floating around? I've seen a java one implemented in amino-cbbs, called LockFreeVector but nothing for .NET so far. Any ideas? 回答1: Well, I couldn't find

Does storing a lot of images in a single directory slow down image retrieval?

不打扰是莪最后的温柔 提交于 2019-12-03 07:14:06
问题 If i have a site where users can upload as many images as they want(think photobucket-like), what is the best way to set up file storage (also, all uploads get a unique random timestamp)? site root --username ----image1.jpg ----image2.jpg ----image3.jpg --anotheruser ----image1.jpg ----image2.jpg ----image3.jpg ... or siteroot --uploads ----image1.jpg ----image2.jpg ----image3.jpg ----image4.jpg ----image6.jpg ... ----image50000.jpg I think the first method is more organized. But i think the

How to return a struct from a function in C++?

五迷三道 提交于 2019-12-03 06:44:32
问题 I've tried on a few different forums and can't seem to get a straight answer, how can I make this function return the struct? If I try 'return newStudent;' I get the error 'No suitable user-defined conversion from studentType to studentType exists.' // Input function studentType newStudent() { struct studentType { string studentID; string firstName; string lastName; string subjectName; string courseGrade; int arrayMarks[4]; double avgMarks; } newStudent; cout << "\nPlease enter student

How to preserve matlab struct when accessing in python?

前提是你 提交于 2019-12-03 06:17:50
I have a mat-file that I accessed using from scipy import io mat = io.loadmat('example.mat') From matlab, example.mat contains the following struct >> load example.mat >> data1 data1 = LAT: [53x1 double] LON: [53x1 double] TIME: [53x1 double] units: {3x1 cell} >> data2 data2 = LAT: [100x1 double] LON: [100x1 double] TIME: [100x1 double] units: {3x1 cell} In matlab, I can access data as easy as data2.LON, etc.. It's not as trivial in python. It give me several option though like mat.clear mat.get mat.iteritems mat.keys mat.setdefault mat.viewitems mat.copy mat.has_key mat.iterkeys mat.pop mat