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
Henrique Dallazuanna
2008-Aug-07 11:55 UTC
[R] Create new dataframes with dames from dataset...
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
Hello all, I am just wondering if any of you are doing most of your scripting with Python instead of R's programming language and then calling the relevant R functions as needed? And if so, what is your experience with this and what sort of software/library do you use in combination with Python to be able to access R's functionality. Is there much of a performance hit either way? (as both are interpreted languages) Thanks, Esmail
Doran, Harold wrote:>> lm(y ~ x-1) >> solve(crossprod(x), t(x))%*%y # probably this can be done more >> efficiently > > > You could do > > crossprod(x,y) instead of t(x))%*%y >that certainly looks more readable (and less error prone) to an R newbie like myself :-)