similar to: how to code it??

Displaying 20 results from an estimated 10000 matches similar to: "how to code it??"

2012 Jul 08
3
Help in Optimization of a function
guRus! I have a function f = exp(x^2-y+(1/z)) Also, x can take values from 1 to 37, y from 2 to 20 and Z from -13 to 51. How can I find the maximum of f using any of the optimization functions please? Is there a way to store the possible values of x, y and Z in a single variable like in a List or in a multi-dimensional array? Thanks for your help Raghu [[alternative HTML version deleted]]
2012 Jul 14
2
writing data into files whose names are in a vector
GuRus How do I use the write function (or write.table or write.csv) to achieve the following please? age=c(32,37,39) names=c("john","peter","jake") I would like create in a directory 3 files each named as john.csv,peter.csv and jake.csv and each file have data from the age vector. That is jon.csv will contain 32, peter.csv will contain 37 and jake.csv will contain
2012 Jul 24
3
Collapsing a vector/data-frame based on the previous values
Hello I have a data frame like this: dput(states) structure(list(Date = c("24/07/2012", "25/07/2012", "26/07/2012", "27/07/2012", "28/07/2012", "24/07/2012", "25/07/2012", "26/07/2012", "27/07/2012", "28/07/2012"), State = c(1L, 1L, 1L, 1L, 1L, -1L, -1L, -1L, 1L, -1L)), .Names = c("Date",
2012 Apr 22
2
difficulty in Formatting time series data
Dear R-Gurus I have a data frame (from CSV file) which has its first column called Date. The Date is in the format mm/dd/yyyy. I was trying to get the weekday for these dates and I tried using wday() and day.of.week() functions and both of them gave me precisely the wrong answers. I think the issue lies in the proper formatting of dates. The class of this column is a factor class and hence I
2010 Jul 28
2
finding the next highest number in an array
Hi I have a sorted array ( in ascending order) and I want to find the subscript of a number in the array which is the the next highest number to a given number. For example,if I have 67 as a given number and if I have a vector x=c(23,36,45,62,79,103,109), then how do I get the subscript 5 from x (to get 79 which is the next highest to 67) without using a for loop? Thx -- 'Raghu'
2010 Jul 06
4
Adding two files into one and vlookup
I have two files with dates and prices in each. The number of rows in each of them will differ. How do I create a new file which contains data from both these files? Cbind and merge are not helpful. For cbind because the rows are not the same replication occurs. Also if I have similar data how do I write a vlookup kind of function? I am giving an example below: Say Price1 file contains the
2010 Jul 12
2
a small puzzle?
I know the following may sound too basic but I thought the mailing list is for the benefit of all levels of people. I ran a simple if statement on two numeric vectors (news1o and s2o) which are of equal length. I have done an str on both of them for your kind perusal below. I am trying to compare the numbers in both and initiate a new vector s as 1 or 0 depending on if the elements in the arrays
2010 Jul 12
6
in continuation with the earlier R puzzle
When I just run a for loop it works. But if I am going to run a for loop every time for large vectors I might as well use C or any other language. The reason R is powerful is becasue it can handle large vectors without each element being manipulated? Please let me know where I am wrong. for(i in 1:length(news1o)){ + if(news1o[i]>s2o[i]) + s[i]<-1 + else + s[i]<--1 + } --
2012 Jun 19
1
Profit calculation
Dear guRus Say I have a price vector, P which is P = c(20,50,40,50) for four consecutive days. My initial equity is say $100 and I re-invest the profits made in each transaction so my equity curve increases. If I go Long on day 1, short and short on day 2, long and long on day 3 and finally short on day 4, how do I calculate the total profits using R? Basically I stay invested at all times. I
2010 Aug 06
3
How to apply apply?!
guRus I have say a dataframe, d and I wish to do the following: 1) For each row, I want to take one particular value of the row and multiply it by 2. How do I do it. Say the data frame is as below: OPEN HIGH LOW CLOSE 1931.2 1931.2 1931.2 1931.2 0 0 0 999.05 0 0 0 1052.5 0 0 0 987.8 0 0 0 925.6 0 0 0 866 0 0 0 1400.2 0 0 0 754.5 0 0 0 702.6 0 0 0 653.25 0 0 0 348 0 0 0 801 866.55 866.55
2010 Aug 06
2
How to read a file inside a function?
Hi I wish to read a file from my local directory from inside a function. I am passing the filename as the argument but this does not work. Say for example function(dat) { dat1=read.csv("D:\\dat.csv",header=TRUE) } If I call funtion(dat) I get the following error. 'Intuitively' i understand this is a mistake but how do I overcome this and how can I read a file name passed as an
2005 Jun 20
2
frequency tables
R-masters, I have a problem that I have been working on for a while and it seems that there may be a simple solution that I have yet to figure out, so I thought that I would venture to post to the help list. Let's say there was a data.frame with three vectors, two that are factors identifying the data, and one that holds the frequency of occurrence (the events are binary, yes or no). I
2010 Jul 07
1
LondonR July Meeting
I am pleased to announce to agenda for next weeks LondonR meeting: LondonR meeting - 13th July 2010 Date:?? ???????? Tuesday 13th July 2010 Time:??????????? 6pm - 9pm Venue:????????? The Shooting Star ??????????????????? 125 - 129 Middlesex Street ??????????????????? E1 7JF ??????????????????? (Nearest Tubes- Liverpool Street, Moorgate or Bank)? Agenda 6.00pm???????? Mango
2011 Jul 05
2
sample function with different proportions
Hi there, I guess this is an easy one, but still:  I would like to randomly sample 0s and 1s but in a way that I end up having for example 70% of 1s and the rest of 0s and not 50:50 as this function does: sample(c(0,1), 100, replace = TRUE) Any recommendations? Many thanks! Ana [[alternative HTML version deleted]]
2008 Nov 22
2
unique columns in a matrix and number of each
I need help determining the unique columns of a matrix and the numbers of each unique column. For example, let's say I have a matrix with 6 columns, 2 of these are filled with the value of 1 and the other 4 are filled with the value of 0. I would then like to have a command that tells me what the unique columns are (so columns with 1s and columns with 0s) and the number of each type of
2003 Nov 11
4
A co-occurrence matrix
Dear R experts, I have a matrix (from some sort of classification) like this: object group [1,] 1 1 [2,] 2 2 [3,] 3 1 [4,] 4 1 [5,] 5 3 And I need something like this: [,1] [,2] [,3] [,4] [,5] [1,] 1 0 1 1 0 [2,] 0 1 0 0 0 [3,] 1 0 1 1 0 [4,] 1 0 1 1 0 [5,] 0 0 0 0 1 where all
2011 Jan 06
2
algorithm help
Hi, I am seeking help on designing an algorithm to identify the locations of stretches of 1s in a vector of 0s and 1s. Below is an simple example: > dat<-as.data.frame(cbind(a=c(F,F,T,T,T,T,F,F,T,T,F,T,T,T,T,F,F,F,F,T) ,b=c(4,12,13,16,18,20,28,30,34,46,47,49,61,73,77,84,87,90,95,97))) > dat a b 1 0 4 2 0 12 3 1 13 4 1 16 5 1 18 6 1 20 7 0 28 8 0 30 9 1 34 10 1 46 11 0
2006 Jan 07
2
VB on Linux with Wine
We have 50 complex applications written in Microsoft Visual Basic 6.0 providing banking solutions. We are seriously thinking of porting our applications to Linux under WINE. Is it possible to do so? Nature of our VB applications: ------------------------------ 1. Extensively used all controls provided in VB 2. Total size of our applications is around 2 million lines 3. Applications are having
2003 Jan 16
3
Announce: pmg -- menu driven GUI using RGtk
Hello all, I've put together a quick and dirty menubar + dialogs + spreadsheet GUI for R using the RGtk package. Performance is not great (OOP is a real memory hog?), the design may be worse, but the hope is that it will be useful in an introductory stats course while we await the arrival of a real gui with ObveRsive and SciViews. The package can be found at
2003 Jan 16
3
Announce: pmg -- menu driven GUI using RGtk
Hello all, I've put together a quick and dirty menubar + dialogs + spreadsheet GUI for R using the RGtk package. Performance is not great (OOP is a real memory hog?), the design may be worse, but the hope is that it will be useful in an introductory stats course while we await the arrival of a real gui with ObveRsive and SciViews. The package can be found at