[R] transforming a .csv file column names as per a particular column rows using R code
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Sun Oct 14 19:16:16 CEST 2012
Not clear to me what your successive rows indicate in your output.
However, you may get something similar to what you want using the reshape2
library:
library(reshape2)
dta1 <- read.csv( text=
"Tool,Step_Number,Data1,Data2
A,1,0,1
A,2,3,2
A,3,2,3
B,1,3,2
B,2,1,2
B,3,3,2
")
# put into long form
dta1l <- melt(dta1,c("Tool","Step_Number"))
# re-cast to wide form
# assuming first row is for tool A, second row is for tool B, etc.
dta2 <- dcast(dta1l,Tool~variable+Step_Number)
On Sun, 14 Oct 2012, siddu479 wrote:
> Hello all,
> I have a .csv file like below.
> Tool,Step_Number,Data1,Data2... etc up to 100 columns.
> A,1,0,1
> A,2,3,1
> A,3,2,1
> .
> .
> B,1,3,2
> B,2,1,2
> B,3,3,2
> .
> .
> ...... so on upto 50 rows
> where the column "*Tool*" has distinct steps in second column
> "*Step_Number*",but both have same entries in Step_Number column.
> I want the output like below.
>
> Tool_1,Data1_1,Data2_1,Tool_2,Data1_2,Data2_2,Tool_3,Data1_3,Data2_3... so
> on
> A,0,1,A,3,1,A,2,1
> B,3,2,B,1,2,B,3,2
> ......
> so on.
>
> basically I am transposing entire data based on a specific column row values
> and renaming the column headers.
> I have a shell script based on awk which can do this task, but the script is
> taking exceptionally higher processing time.
>
> So I am looking for a script in R which can save the time.
> "Please revert to me if the problem description is not clear."
>
> Regards
> Sidda
>
>
>
>
> -----
> Sidda
> Business Analyst Lead
> Applied Materials Inc.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/transforming-a-csv-file-column-names-as-per-a-particular-column-rows-using-R-code-tp4646137.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
More information about the R-help
mailing list