similar to: Speeding up casting a dataframe from long to wide format

Displaying 20 results from an estimated 9000 matches similar to: "Speeding up casting a dataframe from long to wide format"

2008 Oct 30
2
how to convert data from long to wide format ?
Given a dataframe m > m X Y V3 V4 1 1 A 0.5 1.2 2 1 B 0.2 1.4 3 2 A 0.1 0.9 How do I convert m to this with V4 as the cell values ? A B 1 1.2 1.4 2 0.9 NA
2008 Nov 25
2
Reshape matrix from wide to long format
I forgot the reshape equivalent for converting from wide to long format. Can someone help as my matrix is very big. The followin is just an example. > m <- matrix(1:20, nrow=4, dimnames=list(LETTERS[1:4], letters[1:5])) > m a b c d e A 1 5 9 13 17 B 2 6 10 14 18 C 3 7 11 15 19 D 4 8 12 16 20 > as.data.frame(cbind(rep(rownames(m), ncol(m)), rep(colnames(m), each=nrow(m)),
2008 Jul 26
1
Can't get the correct order from melt.data.frame of reshape library.
Simple illustration, > df3 <- data.frame(id=c(3,2,1,4), age=c(40,50,60,50), dose1=c(1,2,1,2), dose2=c(2,1,2,1), dose4=c(3,3,3,3))> df3 id age dose1 dose2 dose41 3 40 1 2 32 2 50 2 1 33 1 60 1 2 34 4 50 2 1 3> melt.data.frame(df3, id.var=1:2, na.rm=T) id age variable value1 3 40 dose1 12 2 50 dose1 23 1
2009 Feb 22
2
How to reshape this data frame from long to wide ?
I tried cast and melt in reshape package, but still can't convert this data frame m m [,1] [,2] [1,] "A" "1" [2,] "A" "2" [3,] "B" "3" to this form. m1 [,1] [,2] [1,] "A" "B" [2,] "1" "3" [3,] "2" NA Please help. [[alternative HTML version deleted]]
2008 Jun 19
4
Any simple way to subset a vector of strings that do contain a particular substring ?
For example, strings <- c("aaaa", "bbbb","ccba"). How to get "aaaa", "bbbb" that do not contain "ba" ? _________________________________________________________________ [[alternative HTML version deleted]]
2008 Jul 31
4
Identifying common prefixes from a vector of words, and delete those prefixes
For example, c("dog.is.an.animal", "cat.is.an.animal", "rat.is.an.animal"). How can I identify the common prefix is ".is.an.animal" and delete it to give c("dog", "cat", "rat") ? Thanks _________________________________________________________________ [[alternative HTML version deleted]]
2008 Jul 15
5
counting number of "G" in "TCGGGGGACAATCGGTAACCCGTCT"
Any better solution than this ? sum(strsplit("TCGGGGGACAATCGGTAACCCGTCT", "")[[1]] == "G") _________________________________________________________________ [[alternative HTML version deleted]]
2008 Sep 13
3
Beautify R scripts in microsoft word
I am generating a report containing several R scripts in the appendix. Is there any way to "beautify" the R source codes in microsoft word, similar to what we see in tinn-R ? Thanks _________________________________________________________________ [[alternative HTML version deleted]]
2008 Jul 08
4
Can R do this ?
I have a folder full of pngs and jpgs, and would like to consolidate them into a pdf with appropriate title and labels. Can this be done via R ? _________________________________________________________________ Easily publish your photos to your Spaces with Photo Gallery. [[alternative HTML version deleted]]
2009 Jan 06
2
Generating GUI for r-scripts
Hi, I have developed some scripts that basically ask for input tab-limited format files, do some processing, and output several pictures or csv. Now I need to have some gui to wrap on top of the scripts, so that end-users can select their input files, adjust some parameters for processing, and select output folder or filenames. Please advice me if there is any tools or project suitable for
2008 Jun 23
2
grouping values
I tried aggregate, apply etc, but can't get the right result. For example, m <- cbind(c(LETTERS[1:5]), c("aa", "bb", "cc", "aa", "cc")) [,1] [,2][1,] "A" "aa"[2,] "B" "bb"[3,] "C" "cc"[4,] "D" "aa"[5,] "E" "cc" how to obtain
2008 Nov 26
2
Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices
My two matrices are roughly the sizes of m1 and m2. I tried using two apply and cor.test to compute the correlation p.values. More than an hour, and the codes are still running. Please help to make it more efficient. m1 <- matrix(rnorm(100000), ncol=100) m2 <- matrix(rnorm(10000000), ncol=100) cor.pvalues <- apply(m1, 1, function(x) { apply(m2, 1, function(y) { cor.test(x,y)$p.value
2008 Dec 07
5
How to force aggregate to exclude NA ?
The aggregate function does "almost" all that I need to summarize a datasets, except that I can't specify exclusion of NAs without a little bit of hassle. > set.seed(143) > m <- data.frame(A=sample(LETTERS[1:5], 20, T), B=sample(LETTERS[1:10], 20, T), C=sample(c(NA, 1:4), 20, T), D=sample(c(NA,1:4), 20, T)) > m A B C D 1 E I 1 NA 2 A C NA NA 3 D I NA 3 4 C I
2008 Jun 25
3
selecting values that are unique, instead of selecting unique values
unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any method to get only 2:10 (i.e. values that are unique) ? _________________________________________________________________ Easily edit your photos like a pro with Photo Gallery. [[alternative HTML version deleted]]
2008 Jun 10
2
Fast method to compute average values of duplicated IDs
Hi, How do I collapse (average in the simplest case) the values of those duplicated ids (i.e., 2, 5, 6, 9) to give a table of unique ids ? t <- cbind(id=c(1:10, 2,5,6,9), value=rnorm(14)) _________________________________________________________________ [[alternative HTML version deleted]]
2008 Dec 04
2
How to optimize this codes ?
How to optimize the for-loop to be reasonably fast for sample.size=100000000 ? You may want to change sample.size=1000 to have an idea what I am achieving. set.seed(143) A <- matrix(sample(0:1, sample.size, TRUE), ncol=10, dimnames=list(NULL, LETTERS[1:10])) B <- list() for(i in 1:10) { B[[i]] <- apply(combn(LETTERS[1:10], i), 2, function(x) { sum(apply(data.frame(A[,x]), 1,
2007 Sep 09
2
Batch mode scenario ("use case")
Hello, I came up with this scenario of the use of batch mode while thinking of back-up schemes to use for myself. However, it could be that the last step needed in this scenario is not supported by rsync! Here's the scenario: At one time, /c/home/wer/work and /e/gold had identical content and were really huge (say, 200 GBytes). After some complex, intricate work, Mr. Wer
2008 Jun 12
1
ADaCGH package crashes at mpiInit()
I have successfully installed ADaCGH package, and trying the example in SegmentPlotWrite did produce alot of pngs and html. I tried again the same example this morning (after a long night of installation), ADaCGH crashes at mpiInit() showing the error: Loading required package: Rmpi ELAN_EXCEPTION @ --: 6 (Initialisation error) elan_init: Can't get capability from environment Aborted I
2008 Jun 24
2
insert new columns to a matrix
Instead of prepend or append new columns to a matrix, how to insert them to a matrix ? For example, I would like to insert 3 new columns after the 5th column of matrix m. _________________________________________________________________ [[elided Hotmail spam]] [[alternative HTML version deleted]]
2008 Jul 25
2
How to preserve the numeric format and digits ?
Instead of > m <- c(400000000, 50000000000) > paste("A", m, "B", sep="") [1] "A4e+08B" "A5e+10B" I want "A400000000" and "A50000000000"