similar to: Dataframe manipulation question

Displaying 20 results from an estimated 11000 matches similar to: "Dataframe manipulation question"

2004 Nov 29
1
Seeking help with a simple loop construction
Hello, I have a df, pp, with five variables: > nobs(pp) q10_1 q10_2 q10_3 q10_4 actcode 1620 1620 1620 1620 1620 I want to create a loop to run four xtabs (the first four variables above by the fifth) and then store the results in a matrix. Below I make my intent clear by showing the output of one xtab which is inserted into a matrix. > a <- xtabs(q10_1 ~
2004 Mar 04
4
A file manipulation question
Hello R experts, The following problem outstrips my current programming knowledge. I have a dataframe with two fields that looks like the following: ID Contract 01 1 01 1 02 2 02 3 02 1 03 2 03 2 03 2 03 1 03 1 03 1 etc... I would like to end up with a dataframe with one row per ID where the value in the contract field would be the
2004 Oct 21
0
Hmisc: Using stratified weighted means (wtd.mean) within a function
Hello list, I have the following function which, as you can see, uses mean: meanratings <- round(apply(stack03[,c(102:121)],2,function(x) (tapply(x ,actcode, mean, na.rm=T))), digits=1) The above function yields the following output: q27a q27b q27c q27d q27e q27f q27g q27h q27i q27j q27k q27l q27m q27o q27p 1 7.8 8.1 7.7 7.9 7.9 NaN NaN 8.4 7.8 7.0 7.6 NaN NaN 7.1 6.0 2
2007 Feb 27
2
str() to extract components
Hi, I have been dabbling with str() to extract values from outputs such as lmer etc and have found it very helpful sometimes. but only seem to manage to extract the values when the output is one simple table, any more complicated and I'm stumped :-( take this example of the extracted coeficients from a lmer analysis... using str(coef(lmer(resp3~b$age+b$size+b$pcfat+(1|sex), data=b)))
2004 Jun 06
4
Request help writing a function
I have been wrestling with this function for quite a while, and am not making headway. 1) I want to apply a function to the following columns of a dataframe: myfunction. <- apply(ph5028[,c(83:107)],2,function(x) ... 2) Within each of the above columns there is a single numeric code, 1, 2 or 3 or an NA. 3) My goal is to determine the percent of time each person used a 2 code. So if a person
2004 Dec 21
2
How to display each symbol in a different color using plot with summary.formula.reverse
Dear R Masters, I have searched high and low (the help archives and my various R reference material and help files) for a solution to what appears to me to be quite a simple problem. In the following syntax, variable n10 has three levels. I would like the symbols that appear in the graph for these three levels to be different colors. The best I have been able to do is to have the Key display
2011 Jul 07
2
kripp.alph error message
Hi! I fairly new to R, have only done pretty basic things so far, so this may be a very basic question..... But I did search the forums and didn't see a solution.... I'm trying to get going with kripp.alpha(). I'm loading data from a file, like this: > library(irr) Loading required package: lpSolve > x <- read.table("foo", comment.char="#", header=TRUE,
2004 Apr 03
3
Seeking help for outomating regression (over columns) and storing selected output
Hello, I have spent considerable time trying to figure out that which I am about to describe. This included searching Help, consulting my various R books, and trail and (always) error. I have been assuming I would need to use a loop (looping over columns) but perhaps and apply function would do the trick. I have unsuccessfully tried both. A scaled down version of my situation is as follows:
2005 Aug 25
1
Attempting to recode elements contained in a list
Hello R-Masters, I have a list 's' with three elements, as shown below. I want to recode a.a, a.a2, and a.a3 to NA if the value in a.a is less than 3. I reivewed my Modern Applied Statistic Book, the online help and did some searching of R-help on the internet. I explored unlist and as.list.data.frame in an attempt to isolate the third element of the list s, but this was not helpful.
2003 Oct 07
3
Problem getting an ifelse statment to work
This is a "long" way; i.e., not necessarily efficient: > qs2 [1] 2 1 1 4 4 4 1 1 1 4 2 4 3 1 4 3 3 2 4 3 > qs9 [1] 4 4 1 3 4 3 1 3 1 4 1 2 3 3 4 4 1 4 2 3 > decision <- function(a, b) { + if (a == 1 || b == 1) return(1) + if (a == 2 || b == 2) return(2) + if (a == 3 || b == 3) return(3) + if (a == 4 || b == 4) return(4) + NA + } > mapply(decision,
2010 Oct 18
2
Getting tripped up on NAs in trying to create new variable
Hello R help: I have the following data: a <- c(NA, 2, 2, 3, 2, NA) b <- c(NA, NA, 3, NA, 1, 3) df <- data.frame(a, b) > df a b 1 NA NA 2 2 NA 3 2 3 4 3 NA 5 2 1 6 NA 3 I want to create variable c such that if there is a 3 in either variable a or variable b, variable c is 1(rows 3, 4 & 6 below). If 3 not in a or b and a value appears in a or b, then c is 0(row 2
2009 Jan 08
1
library error on start up, error on update packages
Hello, I am unable to update packages. I am running R version 2.8.1 (2008-12-22) under VISTA. When I start R I get the following error: Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. Error in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,
2007 Apr 10
2
Kmeans cluster analysis
Hello, I have a data-set containing 22 variables, after appropriate transformations etc I ran a kmeans cluster analysis for 4 clusters , I ran it 20 times to find a result with the lowest within sum of squares. My question is how best do I go about finding out what the characteristics are of each cluster? Is one cluster dominated by a particular set of variables or by a particular
2010 Mar 19
2
Dataframe calculations
Hi everyone, My question will probably seem simple to most of you, but I have spent many hours trying to solve it. I need to perform a series of sequential calculations on my dataframe that move across rows and down columns, and then repeat themselves at each unique 'MM' by 'DD' grouping. Specifically, I want to add 'DEPART' time (24 hr time) to 'TRAVEL'(minutes)
2003 Jan 06
2
R and file size
I will be involved with an analysis based on a file that will be roughly 25 meg. Assuming I have enough memory, is their any limitations to using R on a file this large. Thank you, Gregory L. Blevins Vice President, Partner The Market Solutions Group, Inc. gblevins at marketsolutionsgroup.com Office phone: 612 392-3163 Cell phone: 612 251-0232
2003 Aug 18
1
Would like to apply a weight variable to the summary function in Hmisc
Hello, In the Hmisc package, functions describe and summarize can explicitly take a weight variable. My question is can a weight variable be applied when using 'summary'? For example, using...summary(var1 ~ var2) I would like to weight the data by var 3 (same length). Is this possible? Thanks a lot. Greg Blevins The Market Solutions Group, Inc.
2004 Jun 14
1
error running sammon
Hello, I am inputing a 17 x 17 symetric matrix to sammon. The matrix is a co-occurance matrix with no missing data. If this is at all relevant, running hclust on this matrix works. > samx <- sammon(q23axproduct) I receive the following error: Error in sammon(q23axproduct) : initial configuration must be complete In addition: Warning messages: 1: some of the first 2 eigenvalues are
2008 May 03
1
recode involving a count rule
Hello, R-helpers. I have a data frame below called df. I want to add a variable c, based on the following logic: if df$a < 5 then the first two times this condition is met place a 1 in c, the next two times this condition is met place a 2 in c and when the condition is not met let c equal df$b. The result would look like, dfnew, shown below. a <- rep(c(3,5,7), 4) b <- rep(c(NA,1,2),
2010 Apr 16
3
run R script from Excel VBA
I wrote a R script say called computeCovarMatrix.R and i want to call and run this piece from Excel visual basic. does anyone know how to do that? thanks, KZ [[alternative HTML version deleted]]
2000 Feb 25
1
r-excel interface code
some of you might be interested. i just uploaded the first release of my r-excel interface package to CRAN. it is in contributed extensions nonstandard extensions erich neuwirth -- Erich Neuwirth, Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-38624 Fax: +43-1-4277-9386