similar to: Using apply to generate matrix from rows?

Displaying 20 results from an estimated 5000 matches similar to: "Using apply to generate matrix from rows?"

2006 Jun 20
3
Create variables with common values for each group
Dear all, sorry, this is for sure really basic, but I searched a lot in the internet, and just couldn't find a solution. The problem is to create new variables from a data frame which contains both individual and group variables, such as mean age for an household. My data frame: df hhid h.age 1 10010020 23 2 10010020 23 3 10010126 42 4 10010126 60 5 10010142
2009 Aug 15
1
System is computationally singular and scale of covariates
Dear all, I'm running a self-written numerical optimization routine (hazard model) which includes computing the inverse of the outer product of the score. I have been getting the above error message ("System is computationally singular"), and after some tweaking, I realized that these variables have some high numbers and the problem could be circumvented by scaling them down (i.e.
2009 Sep 20
1
Computing the sum of cross products of rows of a matrix
Hi everyone, I would like to compute the sum of cross products of rows of a matrix. Does anyone know how to do this without an explicit loop for computational efficiency? Below is a code example. Thanks! Stephan # I.e., if I have a matrix like this x <- matrix(rep(c(1,2,3),3),ncol=3) ## > x ## [,1] [,2] [,3] ## [1,] 1 1 1 ## [2,] 2 2 2 ## [3,] 3 3
2009 Jun 25
4
Using by() and stacking back sub-data frames to one data frame
Dear all, I have a code where I subset a data frame to match entries within levels of an factor (actually, the full script uses three difference factors do do that). I'm very happy with the precision with which I can work with R, but since I loop over factor levels, and the data frame is big, the process is slow. So I've been trying to speed up the process using by(), but I got stuck at
2008 Nov 19
2
tapply and any
Dear all, A quick question which I somehow cannto figure out: I want to apply the function "any" to subsets of a dataset in order to create a vector with TRUE/FALSE values, depending on whether a subset has the number 5. I.e., y <- matrix(c(1,2,3,3,4,5,5,6,6,7,5,1,1,3,5,NA,5,1,1,3),ncol=2) > y [,1] [,2] [1,] 1 5 [2,] 2 1 [3,] 3 1 [4,] 3 3 [5,]
2007 Aug 31
2
memory.size help
I keep getting the 'memory.size' error message when I run a program I have been writing. It always it cannot allocate a vector of a certain size. I believe the error comes in the code fragement below where I have multiple arrays that could be taking up space. Does anyone know a good way around this? w1 <- outer(xk$xk1, data[,x1], function(y,z) abs(z-y)) w2 <- outer(xk$xk2,
2007 Aug 28
1
alternate methods to perform a calculation
Consider a data frame (x) with 2 variables, x1 and x2, having equal values. It looks like: x1 x2 1 1 2 2 3 3 Now, consider a second data frame (xk): xk1 xk2 0.5 0.5 1.0 0.5 1.5 0.5 2.0 0.5 0.5 1 1.0 1 1.5 1 2.0 1 0.5 1.5 1.0 1.5 1.5 1.5 2.0 1.5 0.5 2 1.0 2 1.5 2 2.0 2 I have written code to calculate some differences between these
2009 Mar 30
1
Importing csv file with character values into sqlite3 and subsequent problem in R / RSQLite
Dear all, I'm trying to import a csv file into sqlite3 and from there into R. Everything looks fine exepct that R outputs the character values in an odd fashion: they are shown as "\"CHARACTER\"" instead of "CHARACTER", but only if I show the character variable as a vector. Does someone know why this happens? Below is a sample code. The first part is written in
2008 Jul 29
3
finding a faster way to do an iterative computation
useR's, I am trying trying to find out if there is a faster way to do a certain computation. I have successfully used FOR loops and the apply function to do this, but it can take some time to fully compute, but I was wondering if anyone may know of a different function or way to do this: > x [1] 1 2 3 4 5 > xk [1] 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 I want to do:
2003 Jan 03
4
factor analysis (pca): how to get the 'communalities'?
Dear expe-R-ts, I try some test data for a factorAnalysis (resp. pca) in the sense of Prof. Ripley's MASS ? 11.1, p. 330 ff., just to prepare myself for an analysis of my own empirical data using R (instead of SPSS). 1. the data. ## The test data is (from the book of Backhaus et al.: Multivariate ## Analysemethoden. Springer 2000 [9th ed.], p. 300 ff):
2003 May 11
1
Mac OS X canonically decomposed UTF-16 filenames
Hi. I'd like to find some way for Samba to convert the filenames created by Macintosh OS X into something windows can use. According to their docs: http://developer.apple.com/techpubs/macosx/Essentials/SystemOverview/FileSystem/chapter_9_section_13.html filenames are stored as canonically decomposed Unicode 2.1 in UTF-16 format (a sequence of 16-bit codes) Samba running on a
2006 Jul 04
1
using weights in lrm
Dear all, just a quick question regarding weights in logistic regression. I do results <- lrm(y.js ~ h.hhsize + h.death1 + h.ill1 + h.ljob1 + h.fin1 + h.div1 + h.fail1 + h.sex + h.ch.1
2009 Apr 02
2
Selecting all rows of factors which have at least one positive value?
Dear all, I'm trying to select from a dataframe all rows which correspond to a factor (the id variable) for which there exists at least one positive value of a certain variable. As an example: x <- data.frame(matrix(c(rep(11,4),rep(12,3),rep(13,3),rep(0,3),1,rep(0,4),rep(1,2)),ncol=2)) > x X1 X2 1 11 0 2 11 0 3 11 0 4 11 1 5 12 0 6 12 0 7 12 0 8 13 0 9 13 1 10
2010 Nov 17
1
Multiple Line Plots with xyplot
I'm trying to make multiple line plots, each with a different color, using the xyplot command. Specifically, I have an NxK matrix Y and an Nx1 matrix x. I would like the plot to contain a line for each (x, Y[,i]), i=1:K. I know something like xyplot(Y[,1] + Y[,2] + Y[,3] ~ x, type='l') will work, but if Y is large, this notation can get very awkward. Is there a way to do something
2004 Aug 06
2
pull relay problems
i was using multiple ports because that's how i figured i'd have to do it. o, mounting the remote source locally? i'm not familiar with how to do this. i'm also not seeing how to do this in the docs. how would i go about mounting a remote stream? -a.j. On Fri, 27 Apr 2001, Jack Moffitt wrote: > Why are you using multiple ports at all? That's what mountpoints are >
2008 Jan 07
1
Avoiding FOR loops
useR's, I would like to know if there is a way to avoid using FOR loops to perform the below calculation. Consider the following data: > x [,1] [,2] [,3] [1,] 4 11 1 [2,] 1 9 2 [3,] 7 3 3 [4,] 3 6 4 [5,] 6 8 5 > xk Var1 Var2 Var3 1 -0.25 1.75 0.5 2 0.75 1.75 0.5 3 1.75 1.75 0.5 4 2.75 1.75 0.5 5 3.75 1.75
1997 Aug 21
1
R-alpha: another ctest question
I have the following problem. Consider a `classical' test which works for k .ge. 2 samples. Possible interfaces are e.g. xxx.test(x, g) x ... all data, g ... corresponding groups xxx.test(x1, ..., xk) xxx.test(list(x1, ..., xk)) etc etc. Clearly, the first and the second one are nice, but cannot be combined without making `g' (i.e., `group') a named argument. Hence, in
2003 Oct 28
2
outer function problems
I'm pulling my hair (and there's not much left!) on this one. Basically I'm not getting the same result t when I "step" through the program and evaluate each element separately than when I use the outer() function in the FindLikelihood() function below. Here's the functions: Dk<- function(xk,A,B) { n0 *(A*exp(-0.5*(xk/w)^2) + B) } FindLikelihood <-
2009 Nov 04
4
unexpected results in comparison (x == y)
Dear readers of the list, I have a problem a comparison of two data from a vector. The comparison yields FALSE but should be TRUE. I have checked for mode(), length() and attributes(). See the following code (R2.10.0): ----------------------------------------------- # data vector of 66 double data X =
2001 Oct 08
1
Package Install Problem under Win98
Hi, I have tried to install 'tensor' as a new package in these phases: 1. via 'Install package from local Zip-File' in Rgui/Windows98: install.packages("D:/R/_Pakets12MB/tensor.zip", .lib.loc[1], CRAN = NULL) 2. Looking at the library folder, there was now a new entry 'tensor' including some files e.g. \library\tensor\R\tensor.R 3. Then I have done