[R] Create new dataframes with dames from dataset...

Henrique Dallazuanna wwwhsd at gmail.com
Thu Aug 7 13:55:37 CEST 2008


You can do this:

split(x, list(x$Product, x$Type), drop = TRUE)

On Thu, Aug 7, 2008 at 8:21 AM, Lars Modig <eb99lamo at kth.se> wrote:
> Hi
>
> I'm wondering if you could save new data frames with in a loop using the
> names within the data frame... I.e. If you have a data frame as below
>
> Product   Type    Test
> A         One     67
> A         Two     55
> B         One     42
> A         One     55
>
> I would like to generate new dataframes as follow...
>
> A.One (including)
> A         One     67
> A         One     55
>
> A.Two (including)
> A         Two     55
>
> B.One (including)
> B         One     42
>
>
> I've so far has been able to store each data as an indexed eps picture. I
> put a summary of my code below, and as you can see I'm not used to program
> R, and actually it was a long time since I used C or some other software
> also...
>
> Platforms <- sort(unique(data_variable[,3])) # find all platforms sorted
>
> length(Platforms)           # no of platforms
>
>
> for(j in 1: length(Platforms)){                 #
>  row_vector <- which(data_variable[,3]==Platforms[j])   #Find the first
> platform
>  cleaner_1 <- data_variable[row_vector,]                #store it in
> cleaner_1
>
>
>  Motor <- sort(unique(cleaner_1[,5]))       # find all motors for
> platform 1 sorted
>
>   for(i in 1: length(Motor)){
>    row_vector <- which(cleaner_1[,5]==Motor[i])           # find the
> first motor
>    cleaner_type_1 <- cleaner_1[row_vector,]               # store it in
> cleaner_type_1
>
>
>
>    Data_x <-cleaner_type_1[9]
>    Data_y <-cleaner_type_1[10]
>
>
>    hist(Data_x[,], probability=TRUE, breaks=5, main=data_header[9])
>
>
> savePlot(filename = paste(c("C:/pow",j,"_",i), collapse="") ,type = "eps")
> # Save plot with order no i
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list