Re: [R] help identifying clusters

2010-10-20 Thread Nikhil Kaza
Look at clustering task view http://cran.r-project.org/web/views/Cluster.html A simple way to do it is library(cluster) dat$cluster <- pam(dat, 3, stand=T)$clustering plot(dat$lon, dat$lat, col=dat$cluster) Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carol

Re: [R] Using as.polynomial() over a matrix

2010-10-04 Thread Nikhil Kaza
apply(m, 1, function(x){print(as.polynomial(x))}) # Not sure why you are using 2 i.e. applying the formula column wise instead of 1, row wise. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Oct 4, 2010, at 9:10 PM, Raznahan, Arm

Re: [R] removed data is still there!

2010-09-21 Thread Nikhil Kaza
example(factor) iris1$Species <- factor(iris1$Species, drop=T) will get you what you need. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Sep 21, 2010, at 7:41 AM, pdb wrote: I'm confused, hope someone can point out

Re: [R] Finding (Ordered Subvectors)

2010-09-21 Thread Nikhil Kaza
Convert to strings and use grep functions. using c for variable is a bad idea. a <- paste(a, collapse="") b <- paste(b, collapse="") d <- paste(d, collapse="") grepl(b,a) grepl(d,a) Nikhil Kaza Asst. Professor, City and Regional Planning University of No

Re: [R] how to compute when row length is different

2010-09-14 Thread Nikhil Kaza
DF3 <- merge(DF1, DF2, by=c("Sample_id", "RepairHours), all.y=T) DF3$subtract <- DF3$Day_0_Read1-DF3$ ZeroMean Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Sep 14, 2010, at 8:38 AM, rasanpreet wrote: hi

Re: [R] problem with max in a function

2010-09-07 Thread Nikhil Kaza
Comments below On Sep 7, 2010, at 9:37 PM, stephen sefick wrote: Here is a striped down example that is not working because of the 1.00 to 1. Any help would be greatly appreciated. measure_bkf <- (structure(list(measurment_num = c(0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6, 1.8, 2, 2.2, 2.2, 2.4

Re: [R] How to remove all objects except a few specified objects?

2010-08-24 Thread Nikhil Kaza
or use #not checked rm(setdiff(ls(),c("a", "b")) On Aug 24, 2010, at 4:55 AM, Barry Rowlingson wrote: 2010/8/24 500600 : a <- 1 b <- 2 c <- 3 ls()[-a] # set minus to all the objects you want to retain rm(list = ls()[-a] # will remove all the objects - except a ls() # presto Only beca

Re: [R] Quantile Regression and Goodness of Fit

2010-08-23 Thread nikhil kaza
http://www.econ.uiuc.edu/~roger/research/R1/R1.html On Mon, Aug 23, 2010 at 2:15 PM, Steven Ranney wrote: > All - > > Does anyone know if there is a method to calculate a goodness-of-fit > statistic for quantile regressions with package quantreg? > Specifically, I'm wondering if anyone has imple

Re: [R] Help with Vectors and conditional functions

2010-08-19 Thread Nikhil Kaza
In additiion to Ivan's comment, in this case, you are just plotting Yes or No. I think thats not what you want. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 19, 2010, at 3:42 AM, Ivan Calandra wrote: Hi, I ha

Re: [R] replace loops with matrix

2010-08-17 Thread Nikhil Kaza
what is nt? is that a typo for ns? I don't see why you need to calculate lia within the loop. Also library(fBasics) ccl <-rowprod(lia) Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 17, 2010, at 6:22 PM, Hey S

Re: [R] Equality of Vectors

2010-08-13 Thread Nikhil Kaza
?all nikhil.l...@gmail.com On Aug 13, 2010, at 2:49 PM, Downey, Patrick wrote: c(1,2,3) == c(1,2,3) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting

Re: [R] Fw: Error in rowSums REPOST

2010-08-13 Thread Nikhil Kaza
?as.numeric On Aug 13, 2010, at 7:50 AM, Amit Patel wrote: For the query below I have also included the follwing information. Thanks for your replies str(FeaturePresenceMatrix) chr [1:65530, 1:40] "0" "0" "0" "0" "1" "0" "0" "0" "0" ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:65530]

Re: [R] Help with permutation / loops

2010-08-12 Thread nikhil kaza
see whether assets swap2 and vol are > cointegrated.. > > Do you reckon you point me in the right direction as to how to do that? > > Thank you! > Thiago > > -Original Message- > From: Nikhil Kaza [mailto:nikhil.l...@gmail.com] > Sent: 11 August 2010 12:35 > To: F

Re: [R] Help with permutation / loops

2010-08-11 Thread Nikhil Kaza
default device. One way to overcome it is to plot them to a pdf and name them appropriately for each iteration. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 11, 2010, at 6:34 AM, Ferreira, Thiago Alves wrote: Hi everyo

Re: [R] efficient matrix element comparison

2010-08-08 Thread Nikhil Kaza
How about a <- which(row(matchM)!=matchM) b <- matchM[a] diag(collusionM[a,b]) <-1 Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 8, 2010, at 8:43 PM, david h shanabrook wrote: It is a simple problem in that I simpl

Re: [R] Best way to Convert String to Time for comparison?

2010-08-04 Thread Nikhil Kaza
Another way is t1<- c("3:00","1:59","3:00","2:00") t2 <- strptime(t1, format="%H:%M") t2[-4]>t2[-1] Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 4, 2010, at 8:47

Re: [R] Plotting multiple layers(maps) on same page

2010-08-03 Thread Nikhil Kaza
you will have a better luck with R-sig-geo. Unfortunately I could not find an easy way for polygon overlays. plot(Tazshape) lines(ugbshape) if ugbshape was a polyline instead of a polygon. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l

Re: [R] Need help on upper.tri()

2010-08-03 Thread Nikhil Kaza
try using Matrix package instead mat <- Matrix(rnorm(25),5,5) forceSymmetric(mat) The reason your method does not work is because matrix is effectively a vector and the indices increase along rows within a column. Nikhil On Aug 3, 2010, at 7:36 AM, Ron Michael wrote: HI, I am really messi

Re: [R] Collinearity in Moderated Multiple Regression

2010-08-03 Thread Nikhil Kaza
My usual strategy of dealing with multicollinearity is to drop the offending variable or transform one them. I would also check vif functions in car and Design. I think you are looking for lm.ridge in MASS package. Nikhil Kaza Asst. Professor, City and Regional Planning University of North

Re: [R] Collinearity in Moderated Multiple Regression

2010-08-03 Thread Nikhil Kaza
Are x1 and x2 are factors (dummy variables)? cor does not make sense in this case. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 3, 2010, at 9:10 AM, Michael Haenlein wrote: Dear all, I have one dependent variable y and

Re: [R] sorting by date

2010-08-02 Thread Nikhil Kaza
> a <- c( 20071031,20071130, 20071231) b<- sort(as.Date(as.character(a), format="%Y%M%d")) On Aug 2, 2010, at 8:03 PM, Leigh E. Lommen wrote: I am unsure how to sort a column by date if it is currently in the form: MMDD For example the months: 20071031 20071130 20071231 Etc. Re

Re: [R] Dealing with a lot of parameters in a function

2010-08-02 Thread nikhil kaza
use 24 length vectors as parameters instead of numbers e.g. mu=rep(0.5,24) On Mon, Aug 2, 2010 at 11:00 AM, Shentu, Yue wrote: > Hi all, > I'm trying to define and log-likelihood function to work with MLE. > There will be parameters like mu_i, sigma_i, tau_i, ro_i, for i between > 1 to 24. I

Re: [R] removing spatial auto correlation

2010-08-02 Thread nikhil kaza
Try r-sig-geo Look at spdep, geoR, splancs and sp packages for spatial autocorrelation. Also look at http://cran.r-project.org/web/views/Spatial.html On Mon, Aug 2, 2010 at 3:40 AM, nuncio m wrote: > Hi list, > I am trying to fit arima model for a grid of 360x161x338 points, > where

Re: [R] Meaning of following function

2010-08-01 Thread Nikhil Kaza
well "*"(3,2) works but "*"(3,2,3) does not. You should now be able to figure out the logic. It is related to the number of arguments that make sense. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug

Re: [R] question!!

2010-08-01 Thread Nikhil Kaza
?replicate ?apply ?sapply Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 1, 2010, at 2:42 AM, leepama wrote: hi!! imade many codes during these days.. I study Statistics please one more question!! ex1<-function(n,p,

Re: [R] Left Outer Join 2 DF's on Multiple Conditions

2010-07-25 Thread Nikhil Kaza
Look at sqldf package, it is easier to do sql like statements with it. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jul 25, 2010, at 6:10 PM, harsh yadav wrote: Hi, I am trying to execute the following SQL statement using two

Re: [R] Updating a Data Frame

2010-07-22 Thread Nikhil Kaza
mp", "isSynchronized","timediff)] <- cbind(dataF[,"tobiitime"], rep(1,nrow(dataF), (dataF[i,"ruiTime"]-dataF[,"tobiitime"])) } Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jul

Re: [R] replacing elements of distance matrix

2010-07-19 Thread Nikhil Kaza
My mistake, instead of colnames(d1) use substr(colnames(d1),1,1) or similar On Jul 19, 2010, at 2:15 PM, Nikhil Kaza wrote: Michael, You can modify the following code to suit. Also avoid using dist as a variable name since it is a function in base. However, are you sure you want to do

Re: [R] replacing elements of distance matrix

2010-07-19 Thread Nikhil Kaza
;- n.L[[i]]} m2 <- function(i,j){mahalanobis(j, i, var(j))} m3 <- function(k){apply(as.matrix(k),1,m2,as.matrix(k))} d2 <- lapply(x.L, m3) Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jul 19, 2010, at 11:37 AM, Michael Ralph M. Ab

Re: [R] replacing elements of distance matrix

2010-07-19 Thread Nikhil Kaza
replace dist with mahalanobis distance in the following example. a <- cbind(runif(10), sample(1:3, 10, replace=T)) a.L <- split(a,a[,2]) dist.L <- lapply(a.L, dist) Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jul

Re: [R] Help with replacing a substring in a string

2010-07-19 Thread Nikhil Kaza
gsub(".", " ", "abc.degg.hijk", fixed=T) On Jul 19, 2010, at 7:37 AM, Tolga I Uzuner wrote: Actually, I think I got it, need to use gsub. From: Tolga I Uzuner Sent: 19 July 2010 12:11 To: 'r-help@r-project.org' Subject: Help with replacing a substring in a string Dear R Users, I am trying to

Re: [R] Two Dimensional Transformation

2010-07-16 Thread Nikhil Kaza
Unless I am missing something this should do it a<- cbind(runif(10),runif(10)) b <- cbind(a[,1]+a[,2], a[,1]/a[,2]) On Jul 16, 2010, at 7:00 AM, Ravi Ramaswamy wrote: Hi - I am trying to map a two dimensional area A to another two dimensional area B using a function. For instance A =

Re: [R] Cut a within elements by length, not value, of vectors

2010-07-15 Thread Nikhil Kaza
Building on Erik's solution and because it would easier to do date arithmetic.. d1 <- as.character(date) d1 <- ifelse(nchar(d1)<4, paste(0,d1,sep=""),d1) d2 <- as.Date(date, "%m%d") On Jul 15, 2010, at 1:21 PM, btc1 wrote: Hello, I have a vector, "dates", as a series of 3 digit elements,

Re: [R] Batch file export

2010-07-13 Thread Nikhil Kaza
write.csv(z, paste("c:/z_",i,".csv"sep='')) You will have to modify this to prepend 0s. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jul 13, 2010, at 10:03 AM, Michael Haenlein wrote: Dear all,

Re: [R] Substring function?

2010-07-13 Thread Nikhil Kaza
well %in% is really checking if the element is in the set and is not a substring operator. To get the result you want, try content[grepl(search$signatures, content$urls),] For multiple operations you could try sapply(search$signatures, grepl, x=content$urls) Nikhil Kaza Asst. Professor

Re: [R] Batch files process and String parsing

2010-07-07 Thread Nikhil Kaza
?list.files In particular look at pattern argument. ?file.rename ?lapply ?read.table ?"[" Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jul 7, 2010, at 1:11 PM, jd6688 wrote: Here are what i am going to accomplis

Re: [R] how to display the clock time in the loop

2010-07-01 Thread Nikhil Kaza
explicit call to print usually works for me. library(audio) for (i in 1:5){ wait(60) print(Sys.time()) } On Jul 1, 2010, at 4:30 PM, Matt Shotwell wrote: > Try to flush output after printing: > > cat(paste(Sys.time()),"\n"); flush(stdout()) > > On Thu, 2010-07-01 at 16:1

Re: [R] How to delete rows based on replicate values in one column with some extra calcuation

2010-06-29 Thread Nikhil Kaza
You can do this in reshape package as mentioned earlier. However, if you need a solution with aggregate here it is a <- with(data, aggregate(cbind(v1,v2), by=list(x,y,z),sum)) names (a) <- c("x","y","z","v1","v2") Nikhil Kaza Asst. P

Re: [R] How to delete the replicate rows by summing up the numeric columns

2010-06-29 Thread Nikhil Kaza
require(reshape) cast(data, first+second~ ., sum) Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jun 29, 2010, at 3:05 PM, Yi wrote: first=c('u','b','e','k','j','c',&#

Re: [R] How to delete rows based on replicate values in one column with some extra calcuation

2010-06-28 Thread Nikhil Kaza
aggregate(data$third, by=list(data$first), sum) or reqiure(reshape) cast(melt(data), ~first, sum) On Jun 28, 2010, at 9:30 PM, Yi wrote: first=c('u','b','e','k','j','c','u','f','c','e') second = c ('usa ','Brazil ','England','Korea','Japan','China','usa','France','China','England') third=1

Re: [R] optim() not finding optimal values

2010-06-26 Thread Nikhil Kaza
. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jun 26, 2010, at 4:27 PM, Derek Ogle wrote: I am trying to use optim() to minimize a sum-of-squared deviations function based upon four parameters. The basic function is defined as

Re: [R] Spatial: number of independent components?

2010-06-21 Thread Nikhil Kaza
-11 coda_0.13-5 [5] deldir_0.0-12 maptools_0.7-34 [7] foreign_0.8-40 nlme_3.1-96 [9] MASS_7.3-6 Matrix_0.999375-39 [11] lattice_0.18-8 boot_1.2-42 [13] sp_0.9-64 loaded via a namespace (and not attached): [1] grid_2.11.1 tools_2.11.1 Nikhil Kaza Asst. Professor, C

Re: [R] Spatial: number of independent components?

2010-06-21 Thread nikhil kaza
I have spdep 4.58. Perhaps it is deprecated in the new version. Try looking for sparse matrix representation in the help files for spdep Nikhil On Mon, Jun 21, 2010 at 6:10 AM, Daniel Malter wrote: > > as.spam.listw is an unknown function. Is it in a different package? > > Daniel > > other att

Re: [R] Spatial: number of independent components?

2010-06-20 Thread nikhil kaza
Instead of nb2mat try as.spam.listw(nb2listw(cell2nb(...))) this will coerce the adjacency matrix into a sparse matrix representation saving lot of memory. Nikhil On Sun, Jun 20, 2010 at 10:27 PM, Daniel Malter wrote: > > Hi, thanks much. This works in principle. The corrected code is below:

Re: [R] Spatial: number of independent components?

2010-06-20 Thread Nikhil Kaza
lot(g) clusters(g) Nikhil --- Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jun 20, 2010, at 7:17 PM, Daniel Malter wrote: Hi all, I am sorry if this is a very basic quesion, but I have no experience with analyzing spatial data an

Re: [R] Find the 50 highest values in a matrix

2010-06-17 Thread Nikhil Kaza
Matrix is just a vector. So order should work haven't verified the following code. a <- matrix(rnorm(4000*2000), 4000, 2000) b <- order(a, na.last=TRUE, decreasing=TRUE)[1:50] use %% or %/% to get the row# and column #s Nikhil Kaza Asst. Professor, City and Regional Planning Un

Re: [R] Backslash in paste() function

2010-06-16 Thread Nikhil Kaza
On Jun 16, 2010, at 9:23 AM, Stefan Petersson wrote: Just double all the backslashes and you are fine. In order to see the outcome, use cat() (not print). Uwe Ligges On 16.06.2010 09:49, Stefan Petersson wrote: Hi, I'm trying to build a vector of latex commands. However, I need the comm

Re: [R] [R-sig-Geo] How to extract coordinates values from a shapefile?

2010-06-09 Thread Nikhil Kaza
function > coordinates() in sp package gives you the coordinates of > SpatialObjects. > > Regards. > > Rodrigo. > > 2010/6/9 Nikhil Kaza > You need to execute gpclibPermit() to enable gpclib. > > library(maptools) should have issued a warning to that effect. > &

Re: [R] Odp: strange issue with "which" on "seq"

2010-06-09 Thread Nikhil Kaza
which(abs(v - .1) <= .Machine$double.eps) seems to me too cumbersome to write. Any other easier way? all.equal does not quite work Nikhil On Jun 9, 2010, at 7:54 AM, Petr PIKAL wrote: Hi r-help-boun...@r-project.org napsal dne 09.06.2010 13:16:40: Dear R community, I am puzzled by the f

Re: [R] reformat time from hhmm

2010-06-03 Thread nikhil kaza
Minor correction below. Use 0 instead of space if you are using %H On Thu, Jun 3, 2010 at 8:55 PM, nikhil kaza wrote: > ?ifelse > > > t2 <- ifelse(nchar(times)<4, paste("0", times, sep=""), times) > > > strptime(t2, "%H%M") > > Ni

Re: [R] reformat time from hhmm

2010-06-03 Thread nikhil kaza
?ifelse > t2 <- ifelse(nchar(times)<4, paste(" ", times, sep=""), times) > strptime(t2, "%H%M") Nikhil On Thu, Jun 3, 2010 at 5:21 PM, Peter Moore wrote: > Hi, > I'm newish to R, a recent convert from Matlab... So far I'm impressed, and > determined to solve the following problem, which seems

Re: [R] Faster union of polygons?

2010-06-03 Thread nikhil kaza
Reduce might work. Not sure about the speed advantages though. It does simplify code. Unionall <- function(x) Reduce('union', x) leaveout <- Unionall(leaves) On Tue, Jun 1, 2010 at 9:53 PM, Remko Duursma wrote: > Dear R-helpers, > > thanks for yesterday's speeding-up tip. Here is my next query

Re: [R] How to make R automatic?

2010-06-01 Thread Nikhil Kaza
?difftime ?file.info file.info(filename)$mtime Sys.sleep(20) Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Jun 1, 2010, at 10:07 AM, zhangted001 wrote: Hello, I have a question about how R can run automatically. Here is

Re: [R] rounding up to nearest integer

2010-05-24 Thread Nikhil Kaza
?round On May 24, 2010, at 9:26 PM, Mohan L wrote: Dear All, I have a data frame "data" and the below is the str of "data" : $ Feb : int 1 1195 0 11 28 152 24 2 1 1470 ... $ Mar : int 0 1212 0 17 27 184 15 1 1 1311 ... $ Apr : int 2 1244 1 15 23 135 11 0 1 991 ... $ May : int 2

Re: [R] sort a data.frame

2010-05-20 Thread Nikhil Kaza
Try this. dd[order(gsub("chr","",dd$b)),] You need regular expressions if chr is not the only characterstring that is prepended to the numbers. look for ?strsplit Nikhil Kaza University of North Carolina nikhil.l...@gmail.com On May 20, 2010, at 8:28 AM, Yuan Jia

Re: [R] Adding a row at top of dataframe

2010-05-17 Thread Nikhil Kaza
My mistake. cars2 should be initalized to have all the extra rows. cars2 <- data.frame(matrix(rep(NA, prod(dim(cars)) + ncol(cars)), nrow(cars)+1)) cars2[2:nrow(cars2),] <- cars In this way, insertion at any row is possible. Nikhil On May 17, 2010, at 2:46 PM, Peter Ehlers wrote: data(

Re: [R] Adding a row at top of dataframe

2010-05-17 Thread Nikhil Kaza
Works with warnings for me. but your method is better. Nikhil On May 17, 2010, at 1:35 PM, Peter Ehlers wrote: data(cars) cars2 <- cars cars2[2:nrow(cars)+1,] <- cars2[1:nrow(cars),] cars2[1,] <- NA __ R-help@r-project.org mailing list https://sta

Re: [R] Adding a row at top of dataframe

2010-05-17 Thread Nikhil Kaza
Does this work? data(cars) cars2 <- cars cars2[2:nrow(cars)+1,] <- cars2[1:nrow(cars),] cars2[1,] <- NA Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On May 17, 2010, at 11:28 AM, ecvet...@uwaterloo.ca wrote: I hav

Re: [R] All possible paths between two nodes in a flowgraph using igraphs?

2010-05-04 Thread Nikhil Kaza
paths. I am not sure about cycles. But I suppose you can just use the minimum spanning tree and iteratively add the remaining edges to get the cycles. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On May 4, 2010, at 7:34 AM, jcano

Re: [R] Text dependent on a variable in a R function

2010-05-02 Thread nikhil kaza
Thats right. serves me for not checking the code before posting. but paste should work in anycase with collapse or when x is a single parameter. Nikhil On Sun, May 2, 2010 at 10:24 AM, David Winsemius wrote: > > On May 2, 2010, at 10:10 AM, Nikhil Kaza wrote: > > say x is

Re: [R] Text dependent on a variable in a R function

2010-05-02 Thread Nikhil Kaza
say x is the variable. plot(..., title=paste(x, "whatever else"), ...) should work as well. same should work with file names as well. Nikhil On May 1, 2010, at 9:56 PM, R K wrote: Hello, I was wondering if someone could tell me how I can make text dependent on a variable in a R functio

Re: [R] Problem with optimization (constrOptim)

2010-04-29 Thread Nikhil Kaza
rix(c(2,5,6), 3,1)-matrix(c(5,4,2), 3,1)) > } > constrOptim((matrix(c(0,0,0,0,0,0,0,0,0),3,3)), fr) > or > nlm(fr, matrix(c(0,0,0,0,0,0,0,0,0),3,3)) > -- > the function also returned non-comformable error. > Kind regards > Jacob > > > > 2010/4/29 Nikhil

Re: [R] Problem with optimization (constrOptim)

2010-04-28 Thread Nikhil Kaza
fr does not return a scalar. Nikhil On Apr 28, 2010, at 3:35 AM, Człowiek Kuba wrote: Hello, I have the following problem: I have a set of n matrix equations in the form of : [b1] = [A] * [b0] [b2] = [A] * [b1] etc. vertical vectors [b0], [b1], ... are GIVEN. We try to estimate matrix A.

Re: [R] Convert character vector into string

2010-04-28 Thread Nikhil Kaza
?cat On Apr 28, 2010, at 11:21 PM, Ian Seow wrote: Hi, how do I convert a character vector into a string? c("a","b","c") into "a b c" Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.c

Re: [R] Finding the max correlation coefficient value using CCF function

2010-04-28 Thread Nikhil Kaza
try this ?which.max Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Apr 27, 2010, at 11:42 PM, vikrant wrote: Hi All, Suppose I have 2 time series a = 1:20 b = 5:15 and I am finding the cross correlation between these two

Re: [R] 2 simple question

2010-04-24 Thread Nikhil Kaza
If I understand it correctly par(mfrow=c(2,2)) plot(x,y) plot(y,z) . should work. On Apr 24, 2010, at 8:11 AM, Jim Lemon wrote: On 04/24/2010 02:52 AM, tamas barjak wrote: Hi All! I have 2 plain questions: 1.) I know that very primitive question, but that to grant it, that the drawi

Re: [R] is.na<- doesn't seem to work with labelled variables?

2010-04-06 Thread Nikhil Kaza
a <- c(1, 8, 9, 10, 8) a[which(a==8)] <- NA Nikhil On Apr 6, 2010, at 7:31 AM, David Foreman wrote: Dear All, I seem entirely unable to solve what should be a very simple problem. I have imported a SPSS dataset into R using spss.get from Frank Harrell's Hmisc library. The variables ar

Re: [R] Optim() Help, Unusual Error

2010-03-23 Thread Nikhil Kaza
I cannot replicate the error. The following seem to work. Y <- runif(100) comp <- matrix(runif(6500),100,65) par <- rep(.5, 28) optim.results <- optim(par, fn=objective.function, method="Nelder- Mead",comp=comp, Y=Y, n=100) # Not sure why you are selecting the columns in the comp. That is pro

Re: [R] Optim() Help, Unusual Error

2010-03-23 Thread Nikhil Kaza
missed a c(...) here, therefore no par defined. On Mar 23, 2010, at 12:58 PM, ApproxGaussian wrote: par<-(e.1,e.2,e.3,e.4,e.5,e.6,e.7,e.8,e.9,e.10,e.11,e.12,e.13,e.14,e. 15,e.16,e.17,e.18,e.19,e.20,e.21,e.22,e.23,e.24,e.25,e.26,e.27,e.28) __ R-help

Re: [R] Delete all object except some particular ones

2010-03-20 Thread Nikhil Kaza
rm(setdiff(ls(), c("AA", "BB")) should work. On Mar 20, 2010, at 12:27 PM, bogaso.christofer wrote: Dear all, in my working project, I have created huge number of different kind of objects including "AA" and "BB". Now I want to delete all objects except that "AA" and "BB". Is there any proc

Re: [R] Selecting single TAZ based on area proportion

2010-02-08 Thread Nikhil Kaza
try this t <- TazProperties.. v <- aggregate(t$Area, by=list(t$TAZ,t$Props), sum) names(v) <- c("TAZ", "Prop", "area") tapply(v$area, v$Prop, function(x) v$TAZ[which.max(x)]) note that you have to deal with the cases where there is a tie for the maximum. The above just returns the first maximu

Re: [R] Odp: Creating Dummy Variables in R

2009-12-16 Thread Nikhil Kaza
I don't think R will complain, if you use the approach below. However, IF, VVS1 and VVS2 are linearly dependent. Better use the factor approach and define which factor should be the contrast Nikhil On 16 Dec 2009, at 10:12AM, Petr PIKAL wrote: what commands did you use for regression I su

Re: [R] Changing Column names in (Output) csv file

2009-12-16 Thread Nikhil Kaza
I am not sure why you are reading and writing from disk so many times? It will degrade performance. Also avoid loops when you can. just use ONS$labels <- paste(ONS$Var1[i], ONS$Var2[i], ONS$Var3[i], ONS $Var4[i], ONS$Var5[i], ONS$Var6[i], ONS$Var7[i], ONS$Var8[i],ONS $Var9[i], ONS$Var10[i]

Re: [R] Help with missing values in the dataset

2009-12-10 Thread Nikhil Kaza
?merge use all=L On 10 Dec 2009, at 6:06AM, Venkatesh.P wrote: Dear all, I am facing problem with inserting the scheduled day of Observation in the dataset. In the dataset I have only relative time (table 1) and not scheduled day of observation (day 1, 4, 8, 15, 22, 29, 36, 43). I would

Re: [R] conditionally merging adjacent rows in a data frame

2009-12-09 Thread Nikhil Kaza
This is great!! Sqldf is exactly the kind of thing I was looking for, other stuff. I suppose you can speed up both functions 1 and 5 using aggregate and tapply only once, as was suggested earlier. But it comes at the expense of readability. Nikhil On 9 Dec 2009, at 7:59AM, Titus von de

Re: [R] conditionally merging adjacent rows in a data frame

2009-12-08 Thread Nikhil Kaza
How about creating an index using multiple columns. a <- with(d, aggregate(dur, list(rt=rt,tid=tid,mood=mood,roi=roi), sum)) b <- with(d, aggregate(x, list(rt=rt,tid=tid,mood=mood,roi=roi), mean)) c <- merge(a, b, by=c("rt","tid","mood", "roi")) I suppose one could save some time by not r

Re: [R] Help with Nested loop - very slow, can I use an apply?

2009-12-07 Thread Nikhil Kaza
From an old post by Gabor http://tolstoy.newcastle.edu.au/R/help/04/01/0147.html apply (outer (landmark_c,t(store_c),"-"),c(1,4),function(x)sqrt(sum(diag(x*x On 7 Dec 2009, at 10:58PM, dolar wrote: Hi there I have two tables, with longitudinal and latitudinal coordinates. what I

Re: [R] How to get the item in list that is a number?

2009-11-24 Thread Nikhil Kaza
?unlist if I understand you correctly. On 24 Nov 2009, at 5:50PM, Peng Yu wrote: I have the following list. The second item in the list is a number. I'm wondering how to write R code to return this information for any list? $`1` integer(0) $`2` [1] 123 $`3` integer(0) $`4` integer(0) $`5

Re: [R] Do you keep an archive of "useful" R code? and if so - how?

2009-11-22 Thread Nikhil Kaza
I 've used tiddlywiki a personal notebook for other things but not for R. It may be useful to write a css that separates out code from description. http://www.tiddlywiki.com/ On 22 Nov 2009, at 11:53AM, Tal Galili wrote: Hello all, When using R for some time, one comes across more and mor

Re: [R] optim(.. ,"SANN",..)

2009-11-21 Thread Nikhil Kaza
I think the issue is in the function fr, ?apply apply returns a vector or array or list of values So if the inner apply returns a list (this happens when different number of elements in y are positive in different rows) then outer apply cannot coerce it into the correct format to apply the pr

Re: [R] How to transform the Matrix into the way I want it ???

2009-11-09 Thread Nikhil Kaza
This is not an answer to your question, but I have used SparseM package to represent large travel time matrices efficiently. ?as.matrix.ssr if the traveltime matrix is symmetric. On 9 Nov 2009, at 5:24PM, Hongwei Dong wrote: Hi, R users, I'm trying to transform a matrix A into B (see belo

Re: [R] Find the first values in vector

2009-11-09 Thread Nikhil Kaza
How about vec[1:min(which(vec==FALSE))-1] This will return a character(0) vector if vec[1] is FALSE Nikhil On 9 Nov 2009, at 2:38PM, David Winsemius wrote: vec= TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE TRUE TRUE FALSE __ R-help@r-project.

Re: [R] Frequency

2009-11-02 Thread Nikhil Kaza
try sort (table(MAT), decreasing=T) if MAT is your matrix I think this is what you want. though if you want to sort by the first occurrence then it is a different story. Nikhil On 2 Nov 2009, at 1:35PM, Val wrote: V1 v2 v3 v4 569 10 347 10 46 10 18

Re: [R] Re ading and Creating Shape Files

2009-10-29 Thread Nikhil Kaza
Have you tried readShapePoints writePointsShape both in maptools. Also, I don't think you really need a proj4string specified unless you are actually doing some spatial operations such as buffers and distances. I take it that you have already considered and discarded the possibility of

[R] Recode issue

2009-10-22 Thread Nikhil Kaza
I am having trouble with the recode function that is provided in the CAR package. I trying to create a new factors based on existing factors. E.g. >x <- as.factor(1:20) >y <- recode(x, " 1:5='A'; 6:10='B'; 11:15='C'; 16:20='D' ") >y [1] A A A A A 6 7 8 9 A A A A A A A A A A A Levels: 6 7 8 9