similar to: [?]apply functions or for loop

Displaying 20 results from an estimated 6000 matches similar to: "[?]apply functions or for loop"

2011 Oct 11
1
apply for each value
Hello, There has to be a more R'ish way to do this. I have two matrices, one has the values I want, but I want to NA some of them. The other matrix has binary values that tell me if I want to NA the values in the other matrix. I produce a third matrix based on this. I've also tried apply() passing in c(1,2) for rows and columns with no success yet. Example (this works, but I'm
2011 Sep 02
2
previous monday date
Hello, I'm attempting to return the date (in form '%Y-%m-%d') of the Monday previous to the current date. For example: since it is 2011-09-02 today, I would expect 2011-08-29 to be the return value. I found the following in: http://www.mail-archive.com/r-help@r-project.org/msg144184.html Start quote from link: prevmonday <- function(x) 7 * floor(as.numeric(x-1+4) / 7) +
2010 Sep 16
2
question about converting a matrix to a dataframe
First I have a matrix called stocks1: > class(stocks1) [1] "matrix" Here are the first 5 rows of the last 4 columns: > stocks1[1:5,2:5] [,1] [,2] [,3] [,4] [1,] 80.73 31.95 25.4 25.69 [2,] 83.66 31.95 27.12 25.2 [3,] 83.27 32.93 28.74 26.29 [4,] 83.9 34.07 29.77 26.6 [5,] 82.74 35.18 30.24 27.41 Now, why can't I convert this into a dataframe?
2008 May 09
2
which.max2()
Hello, which.max() only returns one index value, the one for the maximum value. If I want the two index values for the two largest values, is this a decent solution, or is there a nicer/better R'ish way? max2 <-function(v) { m=which.max(v) v[m] = -v[m] m2=which.max(v) result=c(m, m2) result } Seems to work ok. Thanks, Esmail
2001 Oct 22
1
No subject
Dear all, I may have overlooked something but the following piece of code causes me trouble: > a_data.frame(1:4) > a X1.4 1 1 2 2 3 3 4 4 > apply(a,2,cat) 1 2 3 4Error in ans[[1]] : subscript out of bounds > apply(a,1,cat) 1234NULL Is this the fact my data.frame has only one dimension ? (and do I forget somewhere (but where ?) to specify not to 'drop'
2007 Nov 14
1
Newbie question about data preparation
I'm new to the R language and still struggling with compactness of R. I haven't got the right compass into the Documentation, too. So, please apologize the possibly stupidiy of my question. I have the following problem: I have two data sets combined in a data.frame x y 1.3 2.2 2.5 3.4 3.1 3.7 8.2 9.5 7.5 8.3 For the analyses of the data I want to group one column (like the classes in a
2005 Jan 24
1
lookups and joins
I have some data coming from SQL sources that I wish to relate in various ways. For reasons only known to our IT people, this can't be done in SQL at present. I am looking for an R'ish technique for looking up new columns on a data frame. As a simple, hardwired example I have tried the following: # This gives me two columns, one the lookup value and the second one # the result column,
2005 Jun 04
3
How to change the value of a class slot
I defined an S4 class with a slot i. Then I wrote a regular function that attempted to increment i. This didn't work, apparently because of the general rule that a function can't change the values of its arguments outside the function. I gather there are ways around it, but the Green book admonishes "cheating on the S evaluation model is to be avoided" (p. 190). Thinking that
2007 Jun 21
9
Undo/reverse zpool create
Hi, If I add an entire disk to a new pool by doing "zpool create", is this reversible? I.e. if there was data on that disk (e.g. it was the sole disk in a zpool in another system) can I get this back or is zpool create destructive? Joubert This message posted from opensolaris.org
2012 Feb 13
1
Retrieve by Id from an R list
Hi everyone, I'm using the poLCA module for some analysis work. Basically, Im using the command >poLCA(f, data=response,nclass=2) This returns a poLCA object (a list) >From this data, I need to retrieve certain indexes, such as[[5]] as seen below. [[5]] Pr(1) Pr(2) Pr(3) class 1: 0 1.0 0.0 class 2: 0 0.5
2013 Apr 03
1
(no subject)
Hello, I want to perform a latent class analysis using poLCA package. My formula is: substances <- cbind(subs1, subs2, subs3, subs4, subs5, subs6) ~ gender+age+education+income+occupation+urban+dbehavior+incarceration+treatment+depression+alcriteria I want to include sample weights in the model, I have read that poLCA does not take into account weights, but when I introduce them, it seems
2000 Jul 28
2
Loop removal?
Dear all, I've got a quite large dataframe (stor) with rows subject and rt (reaction time). I would like to split the reaction times per subject into 6 bins of equal size. Right now, I'm using the following code: bindata <- function(rt) { bindata <- rep(-1,length(rt)) binwidth <- length(rt)/6 bindata[order(rt)[(0*binwidth)+1:(1*binwidth)]] <- 1
2012 Feb 09
1
poLCA and conditional dependence
Dear all, I'm an Sri Lankan undergraduate student. I'm also a total newbie to R. My aim is to use the poLCA package to do a latent class analysis. I found the documentation very helpful, but need to make a small clarification that has stumped me awhile. In my work, I need to make provision for conditional dependence. I'm told that poLCA lets you do that. Unfortunately, I
2007 Apr 18
2
[Bridge] Bridge performance problem
I need some help understanding a strange bridge performance problem I am seeing. Maybe I am making more out of this than I need to. I need your opinions. The setup: The first configuration is two machines connected via a cross over cable: Machine A <====> Machine B The second configuration is two machines with a Linux bridge between them: Machine A <===> Linux Bridge
2009 Feb 25
2
run latent class analysis with R
What's the best approach to running latent class analysis with R? I've downloaded both randomLCA and poLCA packages, but I am interesting in running a standard LCA with individual records (not frequency table) as input data. Wen Gu John Jay College of Criminal Justice445 West 59 StreetNew York, NY 10029 wgu@gc.cuny.edu _________________________________________________________________
2012 Nov 23
2
Samba4 - Bind Config with DHCP
To those who will eb able to assist, Platform: On Ubuntu 12.04 I have used the latest Git version. I have installed isc-dhcp-server and bind9 from the plain apt repositories and have configured DHCP and BIND9 so that DHCP can update DNS entries via the hmac-md5 as so: key rndc-key { algorithm hmac-md5; secret "XXXXXXXXXXXXXXXXXXXX==";} allow unknown-clients; use-host-decl-names on;
2007 Mar 02
5
extracting rows from a data frame by looping over the row names: performance issues
Hi, I have a big data frame: > mat <- matrix(rep(paste(letters, collapse=""), 5*300000), ncol=5) > dat <- as.data.frame(mat) and I need to do some computation on each row. Currently I'm doing this: > for (key in row.names(dat)) { row <- dat[key, ]; ... do some computation on row... } which could probably considered a very natural (and R'ish) way of
2011 Dec 23
2
Latent class multinomial (or conditional) logit using R?
Hi everyone? Does anybody know how can I estimate a Latent class multinomial (or conditional) logit using R? I have tried flexmix, poLCA, and they do not seem to support this model. thanks in advance adan -- View this message in context: http://r.789695.n4.nabble.com/Latent-class-multinomial-or-conditional-logit-using-R-tp4230083p4230083.html Sent from the R help mailing list archive at
2011 Jan 31
2
Latent Class Logit Models in discrete choice experiments
Dear R users, I would like to perform Latent Class Logit Models for the analysis of choice experiments in environmental valuation. This kind of analysis is usually performed with NLogit Software (http://www.limdep.com). I attach the results I usually obtain using NLogit and NLogit model specifications. For Random parameter models and Logit Models I usually perform my analysis with the package
2009 Jul 02
1
Windows zip-files (binaries) for older version of scatterplot3d
Hi, I am working with -poLCA- which uses the package -scatterplot3d- in order to work. However, I work on a restricted server that is not online. The R-version installed there is 2.6. However, running library(poLCA) after installing the most recent -scatterplot3d- on the server leaves me with R telling me that scatterplot3d needs R-version 2.7 or a more recent versions. Since I cannot install the