[R] How to change the order of columns in a data frame?

2012-02-17 Thread Joel Fürstenberg-Hägg
Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20

Re: [R] How to change the order of columns in a data frame?

2012-02-17 Thread Joel Fürstenberg-Hägg
It does not work when using more variables, and my data frames usually contains about thousand columns... Best, Joel fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8), X5=c(5,5,5)) fakedata A X1 X6 X7

Re: [R] How to change the order of columns in a data frame?

2012-02-17 Thread Joel Fürstenberg-Hägg
@Alfredo The X is removed, but the reordering does not work: colnames(df)[1] - Mass columnNames - colnames(df) colnames(df) [1] Mass X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 colnames(df) - gsub(X,,colnames(df)) colnames(df)

Re: [R] How to change the order of columns in a data frame?

2012-02-17 Thread Joel Fürstenberg-Hägg
@ Jim That would work for just a few columns, but I will have around 1000 of them so I need something more generic. best, Joel jim holtman jholt...@gmail.com 17-02-2012 14:44 pos2 - pos1[, c(X, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19,

Re: [R] How to change the order of columns in a data frame?

2012-02-17 Thread Joel Fürstenberg-Hägg
Thank you Sarah, now it works!! Sarah Goslee sarah.gos...@gmail.com 17-02-2012 15:13 Sorry, it should be: fakedata[, order(pos)] A X1 X2 X3 X4 X5 X6 X7 X8 X9 1 0 1 2 3 4 5 6 7 8 9 2 0 1 2 3 4 5 6 7 8 9 3 0 1 2 3 4 5 6 7 8 9 Using order also ensures that

Re: [R] Normality tests on groups of rows in a data frame, grouped based on content in other columns

2011-10-31 Thread Joel Fürstenberg-Hägg
Hi Dennis, Thanks for your prompt response. Best, Joel Dennis Murphy djmu...@gmail.com 30-10-2011 21:11 Hi: Here are a few ways (untested, so caveat emptor): # plyr package library('plyr') ddply(df, .(Plant, Tissue, Gene), summarise, ntest = shapiro.test(ExpressionLevel)) # data.table

[R] Normality tests on groups of rows in a data frame, grouped based on content in other columns

2011-10-30 Thread Joel Fürstenberg-Hägg
Dear R users, I have a data frame in the form below, on which I would like to make normality tests on the values in the ExpressionLevel column. head(df) ID Plant Tissue Gene ExpressionLevel 1 1 p1 t1 g1 366.53 2 2 p1 t1 g2 0.57 3 3 p1 t1 g311.81 4 4

[R] NA Replacement by lowest value?

2010-01-28 Thread Joel Fürstenberg-Hägg
Hi all, I need to replace missing values in a matrix by 10 % of the lowest available value in the matrix. I've got a function I've used earlier to replace negative values by the lowest value, in a data frame, but I'm not sure how to modify it... nonNeg = as.data.frame(apply(orig.df, 2,

Re: [R] NA Replacement by lowest value?

2010-01-28 Thread Joel Fürstenberg-Hägg
Thanks a lot Paul!! Best, Joel Date: Thu, 28 Jan 2010 10:48:37 +0100 From: p.hiems...@geo.uu.nl To: joel_furstenberg_h...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] NA Replacement by lowest value? Joel Fürstenberg-Hägg wrote: Hi all, I need to replace

Re: [R] NA Replacement by lowest value?

2010-01-28 Thread Joel Fürstenberg-Hägg
Fürstenberg-Hägg wrote: Hi all, I need to replace missing values in a matrix by 10 % of the lowest available value in the matrix. I've got a function I've used earlier to replace negative values by the lowest value, in a data frame, but I'm not sure how to modify it... nonNeg

[R] Remove part of string in colname and calculate mean for columns groups

2010-01-15 Thread Joel Fürstenberg-Hägg
Hi all, I have two question. First, I wonder how to remove a part of the column names in a matrix? I would like to remove the _ACCX or _NAX part below. Is there a method where the _ as well as all characters after i can be removed? dim(exprdata) [1] 88 512

[R] How to delete matrix rows based on NA frequency?

2010-01-15 Thread Joel Fürstenberg-Hägg
Hi all, I would like to remove rows from a matrix, based on the frequency of missing values. If there are more than 10 % missing values, the row should be deleted. I use the following to calculate the frequencies, thereby getting a new matrix with the frequencies:

[R] How to calculate the row wise means for grouped columns in matrix?

2010-01-15 Thread Joel Fürstenberg-Hägg
Hi all, I want to calculate the row wise mean of groups of columns in a matrix M. All columns belonging to the same group have the same column name. My idea is to create a new vector V containing these column names, but after first removing the duplicates. Then I would calculate the means

[R] Exchange NAs for mean

2009-12-17 Thread Joel Fürstenberg-Hägg
Hi all, I'm have a matrix (X) with observations as rows and parameters as columns. I'm trying to exchange all missing values in a column by the column mean using the code below, but so far, nothing happens with the NAs... Can anyone see where the problem is? N-nrow(X) # Calculate

[R] Get rid of automatic title from Anova plots

2009-12-10 Thread Joel Fürstenberg-Hägg
Hi all, I'm having a problem when putting the four plots (Residuals vs Fitted, Normal Q-Q, Scale - Location, and Residuals vs Leverage) from an Anova using plot(aov()) into a pdf. A string aov(df[,i] ~ cat)) is added as the main title, so when I use mtext() the two titles are overlapping.

[R] Multiple regression script

2009-12-07 Thread Joel Fürstenberg-Hägg
Hi all, I'm doing Multiple linear regression for a data set. However, it takes a lot of time, as I would like to check every possible combination of factors, evalute the results based for instance on their p values, and then choose the best regression model. So, I wonder if anyone might have

[R] Decision trees with factors and numericals

2009-11-24 Thread Joel Fürstenberg-Hägg
Hi all, Does any of you know how to make a decision tree when the data set contains factors and numericals? I've got a data frame with 3 columns, where y and x1 are numerical and x2 contains factors. Is it possible to use the rpart package, and in that case how? Otherwise, is there

[R] From R to LaTeX to pdf?

2009-11-24 Thread Joel Fürstenberg-Hägg
Hi all, Anyone experienced in the LaTeX format? I'm trying to use the xtable package to create nice anova tables, but how do I do to produce a pdf from the resulting LaTeX table? I've tried WinShell and MiKTeX, but I couldn't get any of them working... Here's an example of the

[R] Error in text.rpart(fit) : fit is not a tree, just a root

2009-11-24 Thread Joel Fürstenberg-Hägg
Hi all, I've tried to make a decision tree for the following data set: Level X Response 279 C 2.4728646 -9.445 341 B 0.5986398 -9.413 343 B 1.1786271 -9.413 384 D 1.4797870 -9.413 390 C 2.0364569 -9.133 391 D

[R] 3D plot, rotatable and with adjustable symbols

2009-11-19 Thread Joel Fürstenberg-Hägg
Hi all, I've tried to make a 3D plot, but have run into some problems. I'd like to have a plot that I can rotate interactively using the mouse, which is possible using the plots3d {R.basic}. However, I would like to change the symbols used as the points, but there's no pch in plot3d().

[R] Trellis settings get lost when printing to pdf

2009-11-13 Thread Joel Fürstenberg-Hägg
Hi all, I've got some problems when changing the trellis settings for the lattice plots. The plots look exactly as I want them to when calling show.settings() as well as when plotting them in the graphical window. But when printing to a pdf file, none of the settings are used!? Does anyone

Re: [R] Loadings and scores from fastICA?

2009-11-12 Thread Joel Fürstenberg-Hägg
? -- Tony Plate Joel Fürstenberg-Hägg wrote: Hi all, Does anyone know how to get the independent components and loadings from an Independent Component Analysis (ICA), as well as principal components and loadings from a Pricipal Component analysis (PCA) using the fastICA

[R] prcomp() PCA vs fastICA() PCA?

2009-11-11 Thread Joel Fürstenberg-Hägg
Hi all, I wonder what the difference is between the functions prcomp and the PCA plotting method used in example 3 from the fastICA package. They give totally different plots. The reason for asking is that I've earlier used prcomp, but now I should do an ICA, and I guess I cannot compare

[R] Loadings and scores from fastICA?

2009-11-11 Thread Joel Fürstenberg-Hägg
Hi all, Does anyone know how to get the independent components and loadings from an Independent Component Analysis (ICA), as well as principal components and loadings from a Pricipal Component analysis (PCA) using the fastICA package? Or perhaps if there's another way to do ICAs in R?

[R] PCA with tow response variables

2009-11-04 Thread Joel Fürstenberg-Hägg
Hi all, I'm new to PCA in R, so this might be a basical thing, but I cannot find anything on the net about it. I need to make a PCA plot with two response variables (df$resp1 and df$resp2) against eight metabolites (df$met1, df$met2, ...) and I don't have a clue how to do... and I've only

[R] Change negative values in column

2009-11-03 Thread Joel Fürstenberg-Hägg
Hi all, I'm trying to write a script that changes all negative values in a data frame column to a small positive value, based on the the minimum value of the column. However, I get the following error: Error in if (x[i] 0) { : argument is of length zero As well, I would minimum

[R] Exclude rows in xyplot

2009-10-27 Thread Joel Fürstenberg-Hägg
Hi all, I'm searching for a way to exclude outliers from my dataset while making xyplots. While plotting using pairs(), I exclude specific row in my data frame and save the settings as a variable which I later include as an argument: # Discard outliers and save settings as idx

[R] Print several xyplots to the same page in a pdf file

2009-10-27 Thread Joel Fürstenberg-Hägg
Hello everybody, I'm using the lattice package and the xyplot to make several graphs like below. However, I can just print the three grouped plots onto one page as I'm putting them into a pdf-file, which gives me a huge amount of pages... Is it possible to put them all, or at least more than

[R] Change positions of columns in data frame

2009-10-23 Thread Joel Fürstenberg-Hägg
Hi all, Probably a simple question, but I just can't find a simple answear in the older threads or anywhere else. I've added some new vectors as columns in a data frame using cbind(). As they're all put as the last columns inte the data frame, I would like to move them to specific positions.

[R] Automatization of non-linear regression

2009-10-22 Thread Joel Fürstenberg-Hägg
Hi everybody, I'm using the method described here to make a linear regression: http://www.apsnet.org/education/advancedplantpath/topics/Rmodules/Doc1/05_Nonlinear_regression.html ## Input the data that include the variables time, plant ID, and severity time -

[R] Division of data frame and deletion of values from column

2009-10-16 Thread Joel Fürstenberg-Hägg
Hi all, I guess this might be an easy question, but I've searched multiple help pages without finding any answear... so now I put my trust in you! I have a data frame (36 variables and 556 observations). One column contains three factors, and I would like to divide the data frame into three

[R] Plot overview xy plots from data frame?

2009-10-14 Thread Joel Fürstenberg-Hägg
Hi, I've got a data frame (556 rows and 36 columns) from which I need to create several xy plots and print to pdf, in order to detect outliers and trends in the data. 16 of the columns contains numerical values, and I would like to create graphs for all combinations. It can be done manually,