as.list
Dear Ivan,
Thanks a lot. I managed to create a list (KANE.LIST) out of my data
set (KANE).
There is still the problem within the barplot function (non-numeric
argument). There are no NA values and just the variable names are non-
numeric...
Thanks
Sibylle
> PA<-read.table("Biotree_partitioning.txt", header=TRUE)
> KANE<-PA[PA$site=="KA"&PA$part=="NE",]
> KANE.LISTs<-subset(KANE, select=c(5:9))
> KANE.LIST<-as.list(KANE.LISTs)
> names(KANE.LIST)<-colnames(KANE)[-c(1:4)]
> for(i in colnames(KANE)[-c(1:4)]){
+ KANE.LIST[[i]]
+ }
>
> barplot(KANE.LIST, ylim=c(-20,20), col=as.numeric(KANE$diversity))
Error in -0.01 * height : non-numeric argument to binary operator
>
> KANE.LIST
$H5
[1] -5.33 -1.17 3.17 -1.83 -1.17 2.50 5.33 -3.78 -8.69 0.33
-2.83 -4.08
$H8
[1] -19.58 -7.33 6.17 -3.83 8.17 21.33 16.67 -9.22 -23.94
2.56 -15.00 -15.92
$S5
[1] -2.75 12.17 16.17 5.00 5.50 7.33 10.56 14.00 4.11 7.33
9.75 8.67
$S8
[1] -11.96 2.50 3.00 -4.83 -9.33 3.17 6.00 4.33 -7.08
-4.56 4.08 -12.08
$C8
[1] -0.23 -0.07 0.09 0.03 0.09 0.22 0.13 -0.07 -0.22 0.01
-0.19 -0.15
> KANE
site part plot diversity H5 H8 S5 S8 C8
1 KA NE 3 2 -5.33 -19.58 -2.75 -11.96 -0.23
2 KA NE 6 2 -1.17 -7.33 12.17 2.50 -0.07
3 KA NE 7 2 3.17 6.17 16.17 3.00 0.09
4 KA NE 10 2 -1.83 -3.83 5.00 -4.83 0.03
5 KA NE 12 2 -1.17 8.17 5.50 -9.33 0.09
6 KA NE 16 2 2.50 21.33 7.33 3.17 0.22
7 KA NE 4 3 5.33 16.67 10.56 6.00 0.13
8 KA NE 5 3 -3.78 -9.22 14.00 4.33 -0.07
9 KA NE 9 3 -8.69 -23.94 4.11 -7.08 -0.22
10 KA NE 15 3 0.33 2.56 7.33 -4.56 0.01
11 KA NE 2 4 -2.83 -15.00 9.75 4.08 -0.19
12 KA NE 8 4 -4.08 -15.92 8.67 -12.08 -0.15
On 27.10.2010, at 15:26, Ivan Calandra wrote:
Hi Sibylle, I was about to send you an email, but I'll modify it thanks to your second! Is PA what you expect? Does it contain the data you want? You should provide some sample data. If the importation worked, try to copy/paste the output of dput(PA), which we can then copy/paste in our console. That function is great to share R objects. If your dataset is too big, try dput(head(PA)), which outputs only the first line of it. Regarding the selection, I think you're doing it wrong. which() returns a logical vector, which is probably not what you're looking for. Maybe: KANE <- PA[PA$Site=="KA" & PA$part=="NE", ] ## the last comma is important to select all the columns for the rows you've chosen Read ?"[" or ?subset to understand more The barplot() might work better then. HTH, Ivan Le 10/27/2010 15:09, "Sibylle St?ckli" a ?crit :
-------- Original-Nachricht --------
Datum: Wed, 27 Oct 2010 15:03:48 +0200
Von: "Sibylle St?ckli"<sibylle.stoeckli at gmx.ch>
An: Rhelp<r-help at r-project.org>
Betreff: as.list
Dear R-users
sorry, here Rcode included (attachment has been removed)
I would like to read a txt file as list, to select rows and
columns, and to create barplots.
(1) selection of parameter site and part: ok
(2) read txt file as list: problem with (1) as there are NA's (the
lines not selected)
(3) barplot: 5 different groups of bars (the selected columns
H5,H8, S5,S8, C8). In each group 4 different bars (parameter
diversity)
--> error in -0.01*height: non-numeric argument to binary operator
PROBLEM
As (2) gives NULL, I think that there is a mistake in my r-script
with the vector/list function.
Thanks
Sibylle
R-Code
PA<-read.table("Biotree_partitioning.txt", header=TRUE)
KANE<-which((PA$site=="KA")&(PA$part=="NE"))
KANE.LIST<-vector("list", dim(PA[KANE,])[2]-4)
KANE.LIST
barplot(KANE.LIST, col=as.numeric(PA$diveristy))
______________________________________________ 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.
-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php
______________________________________________ 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.