stackoverflow1453

Programming&&Games&&Life

Archive for October, 2015

How to turn .csv file to .xts object?

data <- read.table("C:/Users/USERNAME/Desktop/saatlikRSI.csv", header=TRUE, sep = ",")
values<-data$KZ
dates <- data$TAR
datess <- as.POSIXct(dates, format = "%d.%m.%Y %H:%M")
library(xts)
myxts <- as.xts(values, order.by = datess)
plot(myxts)

Calling R functions from C# program using RDotNet Library

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RDotNet;

namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {
            REngine.SetEnvironmentVariables();
            // There are several options to initialize the engine, but by default the following suffice:
            REngine engine = REngine.GetInstance();
          
            engine.Evaluate("dt<-c(3,3,4,4,5,5,6,6)");
            engine.Evaluate("h<-hist(dt)");
            engine.Evaluate("h");
           
            Console.ReadLine();
        }
    }
}

Multihreading

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ThreadingTraining
{
    class Program
    {
        static void Main(string[] args)
        {
            mesajprint m1 = new mesajprint();
            Thread t1 = new Thread(new ThreadStart(m1.prin));
            t1.Name = "t1";

            mesajprint m2 = new mesajprint();
            Thread t2 = new Thread(new ThreadStart(m2.prin));
            t2.Name = "t2";

            mesajprint m3 = new mesajprint();
            Thread t3 = new Thread(new ThreadStart(m3.prin));
            t3.Name = "t3";

            t1.Start();
            t2.Start();
            t3.Start();
        }
    }

    public class mesajprint
    {
        public int sleeptime = 0;
        public static Random random = new Random();

        public mesajprint()
        {

            sleeptime = random.Next(5001);
        }

        public void prin()
        {
            Thread current = Thread.CurrentThread;
            Console.WriteLine(current.Name + " thread will sleep: " + sleeptime + "miliseconds");
            Thread.Sleep(sleeptime);
            Console.WriteLine(current.Name + "done sleeping.");
        }
    }
}

Treeview (Recursive Directory Search)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace TreeViews
{
    public partial class Form1 : Form
    {        
        public Form1()
        {
            InitializeComponent();
        }

        public void TreeOlustur(string dizin, TreeNode ana)
        {
            string[] dizinarayi = Directory.GetDirectories(dizin);

            foreach (string a in dizinarayi)
            {
                var myNode = new TreeNode(a);
                ana.Nodes.Add(myNode);
                TreeOlustur(a, myNode);
            }
        }       

        private void Form1_Load(object sender, EventArgs e)
        {
            agac.Nodes.Add("F:\\");
            TreeOlustur("F:\\", agac.Nodes[0]);
        }    
    }
}

ComboBox

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ComboBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                MessageBox.Show("Item index 0 selected");
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                MessageBox.Show("Item index 1 selected");
            }
        }
    }
}

CheckedListBox

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CheckedListBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            checkedListBox1.Items.Add(textBox1.Text);
        }

        private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue==CheckState.Checked)
            {
                listBox1.Items.Add(checkedListBox1.SelectedItem.ToString());
            }
            else
            {
                listBox1.Items.Remove(checkedListBox1.SelectedItem.ToString());
            }           
        }
    }
}

ListBox

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ListBoxTraining
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //Add
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(textBox1.Text);
            textBox1.Clear();
        }

        //Remove
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            }
        }

        //Exit
        private void button4_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        //Clear
        private void button3_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }


    }
}