Displaying 20 results from an estimated 9000 matches similar to: "Reshape matrix from wide to long 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 Dec 03
2
Speeding up casting a dataframe from long to wide format
Hi,
I am casting a dataframe from long to wide format. The same codes that works for a smaller dataframe would take a long time (more than two hours and still running) for a longer dataframe of 2495227 rows and ten different predictors. How to make it more efficient ?
wer <- data.frame(Name=c(1:5, 4:5), Type=c(letters[1:5], letters[4:5]), Predictor=c("A", "A",
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 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
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 May 19
1
reshape a wide data frame from wide to a long format with metadata columns
Hello R users and developers,
I have a general question about reshaping a wide data frame using the
"reshape" command. I have a data frame consisting of 108 columns that
I would like to convert to a long table and remove the metadata
(embedded in the column names of the wide table) to new metadata
columns in the long format.
#example data frame. NOTE column names contain metadata::
2011 Mar 15
3
how to reshape the data.frame from long to wide in a specific order
Hi,
For example, the data.frame like:
origdata.long <- read.table(header=T, con <- textConnection('
subject sex condition measurement
1 M control 7.9
1 M first 12.3
1 M second 10.7
2 F control 6.3
2 F first 10.6
2 F second 11.1
3 F control 9.5
3
2008 Feb 07
1
Help with package reshape, wide to long
Hello,
I am having difficulty figuring out how to use functions in the
reshape package to perform a wide to long transformation
I have a "wide" dataframe whose columns are like this example:
id1 id2 subject treat height weight age
id1 and id2 are unique for each row
subject and treat are not unique for each row
height, weight, and age are different types of measurements made on
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]]
2012 Mar 19
2
Reshape from long to wide
Hi,
I'm a total beginner in R and this question is probably very simple but I've
spent hours reading about it and can't find the answer. I'm trying to
reshape a data table from long to wide format. I've tried reshape() and
cast() but I get error messages every time and I can't figure why. In my
data, I have the length of two fish from each family. My data table (called
2011 Jul 06
3
Reshape from long to wide format with date variable
Hi,
I need to reshape my dataframe from a long format to a wide format.
Unfortunately, I have a continuous date variable which gives me headaches.
Consider the following example:
> id=c("034","034","016","016","016","340","340")
> date=as.Date(c("1997-09-28", "1997-10-06", "1997-11-04",
2010 Oct 07
3
reshape from wide to long, ordering of "varying"
Hello,
I have data in the following form
age sex Int.Prev.Est.1 Int.Prev.Est.2 Int.Prev.Est.3
Int.Prev.Est.4 Int.Prev.Est.5
93110 93 0 23.75482 57.86592 9.755003
4.343534 4.280714
93610 93 1 53.36475 39.47247 4.381618
1.622119 1.159044
94110 94 0 23.47514 58.23936 10.789339
3.690415 3.805741
94610 94 1
2009 Feb 25
2
reshape from wide to long
Hi,I would like to reshape the following "wide" data set to "long" form. I
would appreciate help with the correct code for "reshape". I tried a few
unsuccessfully.
Thanks.
Chetty
__________________________________________________
dat.1
Grp X0 X3 X6 X12 X25
X501 C 0.5326517 0.6930942 0.9403883 1.157571
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]]
2010 Sep 02
2
reshape to wide format takes extremely long
Hello,
I have a data.frame with the following format:
> head(clin2)
Study Subject Type Obs Cycle Day Date Time
1 A001101 10108 ALB 44.00000 98 1 2004-03-11 14:26
2 A001101 10108 ALP 95.00000 98 1 2004-03-11 14:26
3 A001101 10108 ALT 61.00000 98 1 2004-03-11 14:26
5 A001101 10108 AST 33.00000 98 1 2004-03-11 14:26
I want to transform this
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
2011 Sep 09
4
reshape data from long to wide format
This is my reproducible example:
example<-structure(list(SENSOR = structure(1:6, .Label = c("A", "B", "C",
"D", "E", "F"), class = "factor"), VALUE = c(270, 292.5, 0, 45,
247.5, 315), DATE = structure(1:6, .Label = c(" 01/01/2010 1",
" 01/01/2010 2", " 01/01/2010 3", " 01/01/2010
2011 Jan 20
4
How to reshape wide format data.frame to long format?
Dear list,
I need to convert this data.frame
> names(codesM)
[1] "key" "AMR.pa1.M" "AMR.pa2.M" "AMR.pa3.M" "AMR.pa4.M"
[6] "AMR.pa5.M" "AMR.pa6.M" "AMR.pa7.M" "AMR.pa8.M" "AMR.pa9.M"
[11] "AMR.pa10.M" "AMR.ta1.M" "AMR.ta2.M" "AMR.ta3.M"