[R] Make a table
Dear useR, I have a dataset like this below, > prevRND.dat <- read.table("C:\\workdir\\prevRND.txt", + header=FALSE, # No header. + col.names = c("X","Y","Z"), + sep = ",") > prevRND.dat X YZ 1 A A 0.950933 2 A B 0.143600 3 A C 0.956133 4 B A 0.000533 5 B B 0.986467 6 B C 0.032066 7 C A 0.005333 8 C B 0.00 9 C C 0.009266 How can I make that data above as table, Y XA B C A 0.950933 0.143600 0.956133 B 0.000533 0.986467 0.032066 C 0.005333 0.00 0.009266 I cannot use table() or ftable() functions because the 3rd column (Z) is probability. Are there any function to make a table as I want? Kind regards, Muhammad Subianto __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Make a table
Thanks to all of you. That's what I want. Best wishes, Muhammad Subianto Try tapply(prevRND.dat$Z, list(X=prevRND.dat$X, Y=prevRND.dat$Y), mean) __ Andy Jaworskitry: try: tapply( Z, list( X, Y ), mean ) -- Bendix Carstensen How about: xtabs(Z ~ X + Y, data = prevRND.dat) Y X ABC A 0.950933 0.143600 0.956133 B 0.000533 0.986467 0.032066 C 0.005333 0.00 0.009266 HTH, Marc Schwartz __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to show which variables include in plot of classification tree
Dear all For my research, I am learning classification now. I was trying some example about classification tree pakages, such as tree and rpart, for instance, in Pima.te dataset have 8 variables (include class=type): library(rpart) library(datasets) pima.rpart <- rpart(type ~ npreg+glu+bp+skin+bmi+ped+age,data=Pima.te, method='class') plot(pima.rpart, uniform=TRUE) text(pima.rpart) summary(pima.rpart) In the result I found only 5 variables: npreg, glu, bmi, ped, and age were showing in the plot. Now, I have 50 variables in my dataset. The result my classification tree very difficult to know which variables showing in the plot. Are there any trick which variables are showing in plot. Thanks for your help. Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Remove comma (,) in data set
Dear R-helper, I am new learning R. Now, I have a data set like: 24,2,3,3,1,1,2,3,0,1 45,1,3,10,1,1,3,4,0,1 43,2,3,7,1,1,3,4,0,1 42,3,2,9,1,1,3,3,0,1 36,3,3,8,1,1,3,2,0,1 19,4,4,0,1,1,3,3,0,1 38,2,3,6,1,1,3,2,0,1 21,3,3,1,1,0,3,2,0,1 27,2,3,3,1,1,3,4,0,1 45,1,1,8,1,1,2,2,1,1 ... with 3730 rows I want to remove comma (,) in data set. The result like: 24 2 3 3 1 1 2 3 0 1 45 1 3 10 1 1 3 4 0 1 43 2 3 7 1 1 3 4 0 1 42 3 2 9 1 1 3 3 0 1 36 3 3 8 1 1 3 2 0 1 19 4 4 0 1 1 3 3 0 1 38 2 3 6 1 1 3 2 0 1 21 3 3 1 1 0 3 2 0 1 27 2 3 3 1 1 3 4 0 1 45 1 1 8 1 1 2 2 1 1 ... How can I do it. Thanks you for your help. Best regards, Muhammad Subianto __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] R packages install problems linux - X not found (WhiteBoxEL 3)
Maybe you can try with the other RHEL clone like CentOS-3: http://install.linux.duke.edu/pub/linux/add-on/distrib/centos-3.1/i386/rpms/R-1.9.0-0.duke.1.el3.i386.rpm http://install.linux.duke.edu/pub/linux/add-on/distrib/centos-3.1/i386/srpms/R-1.9.0-0.duke.1.el3.src.rpm Best wishes, Muhammad Subianto On this day 09/08/2004 04:12 PM, Marc Schwartz wrote: On Mon, 2004-08-09 at 08:13, Dr Mike Waters wrote: Marc, Sorry for the confusion yesterday - in my defence, it was very hot and humid here in Hampshire (31 Celsius at 15:00hrs and still 25 at 20:00hrs). What had happened was that I had done a clean install of WB Linux, including the XFree86 and other developer packages. However, the on-line updating system updated the XFree86 packages to a newer sub version. It seems that it didn't do this correctly for the XFree86 developer package, which was missing vital files. However it showed up in the rpm database as being installed (i.e. rpm -qa | grep XFree showed it thus). I downloaded another rpm for this manually and I only forced the upgrade because it was the same version as already 'installed' (as far as the rpm database was concerned). I assumed that all dependencies were sorted out through the install in the first place. OK, that helps. I still have a lingering concern that, given the facts above, there may be other integrity issues in the RPM database, if not elsewhere. From reading the WB web site FAQ's (http://www.whiteboxlinux.org/faq.html) , it appears that they are using up2date/yum for system updates. Depending upon the version in use, there have been issues especially with up2date (hangs, incomplete updates, etc.) which could result in other problems. I use yum via the console here (under FC2), though I note that a GUI version of yum has been created, including replacing the RHN/up2date system tray alert icon. A thought relative to this specifically: If there is or may be an integrity problem related to the rpm database, you should review the information here: http://www.rpm.org/hintskinks/repairdb/ which provides instructions on repairing the database. Note the important caveats regarding backups, etc. The two key steps there are to remove any residual lock files using (as root): rm -f /var/lib/rpm/__* and then rebuilding the rpm database using (also as root): rpm -vv --rebuilddb I think that there needs to be some level of comfort that this basic foundation for the system is intact and correct. I only mentioned RH9 to show that I had some familiarity with the RedHat policy of separating out the 'includes' etc into a separate developer package. Once all this had been sorted out, I was then left with a compilation error which pointed to a missing dependency or similar, which was not due to missing developer packages, but, as you and Prof Ripley correctly point out, from the R installation itself. Having grown fat and lazy on using R under the MS Windows environment, I was struggling to identify the precise nature of this remaining problem. As regards the R installation, I did this from the RH9 binary for version 1.9.1, as I did not think that the Fedora Core 2 binary would be appropriate here. Perhaps I should now compile from the source instead? I would not use the FC2 RPM, since FC2 has many underlying changes not the least of which includes the use of the 2.6 kernel series and the change from XFree86 to x.org. Both changes resulted in significant havoc during the FC2 testing phases and there was at least one issue here with R due to the change in X. According to the WB FAQs: "If you cannot find a package built specifically for RHEL3 or WBEL3 you can try a package for RH9 since many of the packages in RHEL3 are the exact same packages as appeared in RH9." Thus, it would seem reasonable to use the RH9 RPM that Martyn has created. An alternative would certainly be to compile R from the source tarball. In either case, I would remove the current installation of R and after achieving a level of comfort that your RPM database is OK, reinstall R using one of the above methods. Pay close attention to any output during the installation process, noting any error or warning messages that may occur. If you go the RPM route, be sure that the MD5SUM of the RPM file matches the value that Martyn has listed on CRAN to ensure that the file has been downloaded in an intact fashion. These are my thoughts at this point. You need to get to a point where the underlying system is stable and intact, then get R to the same state before attempting to install new packages. HTH, Marc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Take a levels
Dear all, How can I take a levels from a dataset. For example, data(iris) x.iris <- iris[,1:4] y.iris <- iris[,5] > y.iris [1] setosa setosa setosa setosa setosa setosa [7] setosa setosa setosa setosa setosa setosa [139] virginica virginica virginica virginica virginica virginica [145] virginica virginica virginica virginica virginica virginica Levels: setosa versicolor virginica I want like, y.iris level are, [] setosa versicolor virginica Best regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Take a levels
Thanks you very much. > > levels(y.iris) > Best regards, Muhammad Subianto [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to add some of data in the first place dataset
Dear R-help, First I apologize if my question is quite simple. I need add some of data in the first place my dataset, how can I do that. I have tried with rbind, but I did not succes. 0.1 3.6 0.4 0.9 rose 4.1 4.0 1.2 1.2 rose 4.4 3.2 1.9 0.5 rose 4.6 1.1 1.1 0.2 rose For example, > data(iris) > iris[1:10,] Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa 7 4.6 3.4 1.4 0.3 setosa 8 5.0 3.4 1.5 0.2 setosa 9 4.4 2.9 1.4 0.2 setosa 10 4.9 3.1 1.5 0.1 setosa > The result something like this, 0.1 3.6 0.4 0.9 rose 4.1 4.0 1.2 1.2 rose 4.4 3.2 1.9 0.5 rose 4.6 1.1 1.1 0.2 rose 5.1 3.5 1.4 0.2 setosa 4.9 3.0 1.4 0.2 setosa 4.7 3.2 1.3 0.2 setosa 4.6 3.1 1.5 0.2 setosa 5.0 3.6 1.4 0.2 setosa 5.4 3.9 1.7 0.4 setosa 4.6 3.4 1.4 0.3 setosa 5.0 3.4 1.5 0.2 setosa 4.4 2.9 1.4 0.2 setosa 4.9 3.1 1.5 0.1 setosa Sincerely, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Re: How to add some of data in the first place dataset
Thanks all for your help. Kind regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to change variables in datasets automatically
Dear R-helpers, Suppose I have a dataset, data(iris) a <- data.frame(Sepal.Length=c(1:4), Sepal.Width=c(2:5), Petal.Length=c(3:6), Petal.Width=c(4:7), Species=rep("rosa",4)) b <- iris[1:10,] newtest.iris <- rbind(a,b) > newtest.iris Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 1.0 2.0 3.0 4.0rosa 2 2.0 3.0 4.0 5.0rosa 3 3.0 4.0 5.0 6.0rosa 4 4.0 5.0 6.0 7.0rosa 11 5.1 3.5 1.4 0.2 setosa 21 4.9 3.0 1.4 0.2 setosa 31 4.7 3.2 1.3 0.2 setosa 41 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa 7 4.6 3.4 1.4 0.3 setosa 8 5.0 3.4 1.5 0.2 setosa 9 4.4 2.9 1.4 0.2 setosa 10 4.9 3.1 1.5 0.1 setosa I want to change each labels (variables) like: Sepal.Length=SL, Sepal.Width=SW, Petal.Length=PL, Petal.Width=PW, and Species=Class. Then I want to change each cell in Species variable like rosa=0 and setosa=1. The result something like this, > NewIris SL SW PL PW Class 1 1.0 2.0 3.0 4.0 0 2 2.0 3.0 4.0 5.0 0 3 3.0 4.0 5.0 6.0 0 4 4.0 5.0 6.0 7.0 0 5 5.1 3.5 1.4 0.2 1 6 4.9 3.0 1.4 0.2 1 7 4.7 3.2 1.3 0.2 1 8 4.6 3.1 1.5 0.2 1 9 5.0 3.6 1.4 0.2 1 10 5.4 3.9 1.7 0.4 1 11 4.6 3.4 1.4 0.3 1 12 5.0 3.4 1.5 0.2 1 13 4.4 2.9 1.4 0.2 1 14 4.9 3.1 1.5 0.1 1 > I can do it the result above like this, > Class <- ifelse(newtest.iris$Species=="rosa", 0, 1) > NewIris <- data.frame(SL = newtest.iris$Sepal.Length, +SW = newtest.iris$Sepal.Width, +PL = newtest.iris$Petal.Length, +PW = newtest.iris$Petal.Width, +Class) Because I have more variables in my datasets which I must to change. Is there any way to change automatically and which library contains a function to compute that? I would be very happy if anyone could help me. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to change variables in datasets automatically
Excellent, this is exactly what I was looking for. Many thanks and best regards, Muhammad Subianto On 4/29/05, Liaw, Andy <[EMAIL PROTECTED]> wrote: > Try: > > a <- data.frame(Sepal.Length=1:4, Sepal.Width=2:5, > Petal.Length=3:6, Petal.Width=4:7, > Species=rep("rosa",4)) > b <- iris[1:10,] > newtest.iris <- rbind(a,b) > names(newtest.iris) <- c("SL", "SW", "PL", "PW", "Class") > newtest.iris$Class <- as.numeric(newtest.iris$Class) - 1 > > HTH, > Andy > > > From: Muhammad Subianto > > > > Dear R-helpers, > > Suppose I have a dataset, > > data(iris) > > a <- data.frame(Sepal.Length=c(1:4), Sepal.Width=c(2:5), > > Petal.Length=c(3:6), Petal.Width=c(4:7), Species=rep("rosa",4)) > > b <- iris[1:10,] > > newtest.iris <- rbind(a,b) > > > newtest.iris > >Sepal.Length Sepal.Width Petal.Length Petal.Width Species > > 1 1.0 2.0 3.0 4.0rosa > > 2 2.0 3.0 4.0 5.0rosa > > 3 3.0 4.0 5.0 6.0rosa > > 4 4.0 5.0 6.0 7.0rosa > > 11 5.1 3.5 1.4 0.2 setosa > > 21 4.9 3.0 1.4 0.2 setosa > > 31 4.7 3.2 1.3 0.2 setosa > > 41 4.6 3.1 1.5 0.2 setosa > > 5 5.0 3.6 1.4 0.2 setosa > > 6 5.4 3.9 1.7 0.4 setosa > > 7 4.6 3.4 1.4 0.3 setosa > > 8 5.0 3.4 1.5 0.2 setosa > > 9 4.4 2.9 1.4 0.2 setosa > > 10 4.9 3.1 1.5 0.1 setosa > > > > I want to change each labels (variables) like: > > Sepal.Length=SL, Sepal.Width=SW, > > Petal.Length=PL, Petal.Width=PW, and Species=Class. Then I want to > > change each cell > > in Species variable like rosa=0 and setosa=1. The result > > something like this, > > > > > NewIris > > SL SW PL PW Class > > 1 1.0 2.0 3.0 4.0 0 > > 2 2.0 3.0 4.0 5.0 0 > > 3 3.0 4.0 5.0 6.0 0 > > 4 4.0 5.0 6.0 7.0 0 > > 5 5.1 3.5 1.4 0.2 1 > > 6 4.9 3.0 1.4 0.2 1 > > 7 4.7 3.2 1.3 0.2 1 > > 8 4.6 3.1 1.5 0.2 1 > > 9 5.0 3.6 1.4 0.2 1 > > 10 5.4 3.9 1.7 0.4 1 > > 11 4.6 3.4 1.4 0.3 1 > > 12 5.0 3.4 1.5 0.2 1 > > 13 4.4 2.9 1.4 0.2 1 > > 14 4.9 3.1 1.5 0.1 1 > > > > > I can do it the result above like this, > > > > > Class <- ifelse(newtest.iris$Species=="rosa", 0, 1) > > > NewIris <- data.frame(SL = newtest.iris$Sepal.Length, > > + SW = newtest.iris$Sepal.Width, > > +PL = newtest.iris$Petal.Length, > > +PW = newtest.iris$Petal.Width, > > +Class) > > > > Because I have more variables in my datasets which I must to change. > > Is there any way to change automatically and which library contains a > > function to compute that? > > I would be very happy if anyone could help me. > > Thank you very much in advance. > > > > Kindly regards, > > Muhammad Subianto > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > > -- > Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Change the result data
Dear R-helper, I have a data like: hec.data <-array(c(5,15,20,68,29,54,84,119,14,14,17,26,16,10,94,7), dim=c(4,4), dimnames=list(eye=c("Green","Hazel", "Blue", "Brown"), hair=c("Black", "Brown", "Red", "Blond"))) as.data.frame(as.table(hec.data)) > as.data.frame(as.table(hec.data)) eye hair Freq 1 Green Black5 2 Hazel Black 15 3 Blue Black 20 4 Brown Black 68 5 Green Brown 29 6 Hazel Brown 54 7 Blue Brown 84 8 Brown Brown 119 9 Green Red 14 10 Hazel Red 14 11 Blue Red 17 12 Brown Red 26 13 Green Blond 16 14 Hazel Blond 10 15 Blue Blond 94 16 Brown Blond7 > I want to extract like, Green Black Green Black Green Black Green Black Green Black Hazel Black Hazel Black Hazel Black Hazel Black . . . Brown Blond Brown Blond Brown Blond Brown Blond Brown Blond Brown Blond Brown Blond How can I do it. Thanks you for your help. Best regards, Muhammad Subianto http://article.gmane.org/gmane.comp.lang.r.general/14604,14610 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to make label in multi plot
Dear R-Help, As a reference about multi plot, http://finzi.psych.upenn.edu/R/Rhelp02a/archive/48725.html I want to know how can I make a label for each row. I mean like, - -- || || || Group A | plot1 | | plot 2 | | plot 3 | || || || -- -- - || Group B | plot 4 | || - I would be very happy if anyone could help me. Thank you very much in advance. Sincerely, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to convert color to black & white
Dear all, Could someone please explain to me how to convert color to black & white. For example: barplot(1:5,col = rainbow(5)) Because I need to print my plot to save my ink color printer. I don't want to convert to grayscale, but keep it as an RGB. I would be very happy if anyone could help me. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to convert color to black & white
Thank's you very much. But I need the plot with color not gray. Best wishes, Muhammad Subianto On this day 5/14/2005 3:05 AM, [EMAIL PROTECTED] wrote: Muhammad, Here's one option: barplot(1:5,col=gray(seq(0,1,length=5))) Norm Olsen Fisheries and Oceans Canada -Original Message- From: [EMAIL PROTECTED] To: R-help@stat.math.ethz.ch Sent: 5/13/2005 11:40 AM Subject: [R] How to convert color to black & white Dear all, Could someone please explain to me how to convert color to black & white. For example: barplot(1:5,col = rainbow(5)) Because I need to print my plot to save my ink color printer. I don't want to convert to grayscale, but keep it as an RGB. I would be very happy if anyone could help me. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to make label in multi plot
Dear Dr. Paul Murrel, Yes, this is exactly what I need. Thank's you very much. Best wishes, Muhammad Subianto On this day 5/16/2005 5:36 AM, Paul Murrell wrote: Hi (cc'ed to Pierre Lapointe because this should answer the question about "[R] Centered overall title with layout()" as well) Muhammad Subianto wrote: Dear R-Help, As a reference about multi plot, http://finzi.psych.upenn.edu/R/Rhelp02a/archive/48725.html I want to know how can I make a label for each row. I mean like, - -- || || || Group A | plot1 | | plot 2 | | plot 3 | || || || -- -- - || Group B | plot 4 | || - Two ways (at least): (i) use an outer margin ... ooma <- par(oma=c(0, 5, 0, 0)) layout(rbind(c(1, 2, 3), c(0, 4, 0))) plot(1:10, main="Plot 1") olas <- par(las=2) mtext("Group A", side=2, adj=1, outer=TRUE, at=0.75) par(olas) plot(1:20, main="Plot 2") plot(1:30, main="Plot 3") plot(1:40, main="Plot 4") olas <- par(las=2) mtext("Group B", side=2, adj=1, outer=TRUE, at=0.25) par(olas) # new page! plot(1:40, main="Plot 5") par(ooma) (ii) create an extra row/coloumn in the layout for the labels: layout(rbind(c(1, 2, 3, 4), c(5, 0, 6, 0)), widths=c(2, 5, 5, 5)) # "plot 1" is label for row 1 omar <- par(mar=rep(0, 4)) plot.new() text(0.5, 0.5, "Group A", cex=2) par(omar) plot(1:10, main="Plot 1") plot(1:20, main="Plot 2") plot(1:30, main="Plot 3") # "plot 5" is label for row 2 omar <- par(mar=rep(0, 4)) plot.new() text(0.5, 0.5, "Group B", cex=2) par(omar) plot(1:40, main="Plot 4") # new page! plot(1:40, main="Plot 5") Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to convert color to black & white - Solve
Dear Uwe, Thank for you advice. Now, I know how to do with my color printer to print black and white. James Holtman have advise me about that. Then I use a simple color like this to use my picture. print.bw4 <-c(blueF = "#FF", redF = "#FF", salmon.light = "#dd9955", yellowF = "#00") barplot(1:4,col = print.bw4) Best, Muhammad Subianto On this day 5/16/2005 2:42 PM, Uwe Ligges wrote: Muhammad Subianto wrote: Thank's you very much. But I need the plot with color not gray. So you want a colorful rgb plot, OK, fine with your code below. Now you want to print it black and white: This is now a question for the folks who wrote your printer driver, but not for R-help. Uwe Ligges Best wishes, Muhammad Subianto On this day 5/14/2005 3:05 AM, [EMAIL PROTECTED] wrote: Muhammad, Here's one option: barplot(1:5,col=gray(seq(0,1,length=5))) Norm Olsen Fisheries and Oceans Canada -Original Message- From: [EMAIL PROTECTED] To: R-help@stat.math.ethz.ch Sent: 5/13/2005 11:40 AM Subject: [R] How to convert color to black & white Dear all, Could someone please explain to me how to convert color to black & white. For example: barplot(1:5,col = rainbow(5)) Because I need to print my plot to save my ink color printer. I don't want to convert to grayscale, but keep it as an RGB. I would be very happy if anyone could help me. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to convert array to c()
Dear R-helper, Is there possible to make this array: > a <- array(1:12, c(4, 3)) > a [,1] [,2] [,3] [1,]159 [2,]26 10 [3,]37 11 [4,]48 12 > like: c(1,5,9) c(2,6,10) c(3,7,11) c(4,8,12) Thank you very much in advance. Regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to convert array to c()
Dear all, Many thanks for your help. Regards, Muhammad Subianto On this day 5/18/2005 4:57 PM, Liaw, Andy wrote: > Is this what you want? > > >>split(a, row(a)) > > $"1" > [1] 1 5 9 > > $"2" > [1] 2 6 10 > > $"3" > [1] 3 7 11 > > $"4" > [1] 4 8 12 > > Andy On this day 5/18/2005 5:15 PM, [EMAIL PROTECTED] wrote: Look at ?assign, one possible answer is shown in the examples. Modified for your example: for (i in 1:nrow(a)) { nam <- paste("r",i, sep=".") assign(nam, a[i,]) } would give you four separate objects r.1 to r.4 containing the 4 vectors. Not sure if that's exactly what you wanted though. Norm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Problem with label name in mosaics plot
Dear all R-help, I have a problem with label name in mosaics plot if I use more 4 variables. Let see with my toy example. library(vcd) toy.mosaics <- array(c(96,44,1,138,64,2,117,56,6,75,48,5,72,49,6,83,60,8,140, 43,1,171,65,4,152,58,9,101,51,9,102,58,10,111,67,16,24, 5,2,18,7,1,16,7,3,12,6,4,6,8,3,4,10,4,21,4,1,25,6,2,20, 5,1,17,5,111,14,50,1,13,5,8), dim=c(4,4,2,3,2,6), dimnames=list( Hair=c("Black", "Brown", "Red", "Blond"), Eye=c("Green", "Hazel", "Blue", "Brown"), Race=c("White", "NonWhite"), Opinion=c("Yes", "No", "Und"), Sex=c("Male", "Female"), Age=c("18-25", "26-35", "36-45", "46-55", "56-65", "66+"))) # 2 variables mosaicplot(~ Hair+Eye, data=toy.mosaics, color = TRUE) x11() # 3 variables mosaicplot(~ Hair+Eye+Sex, data=toy.mosaics, color = TRUE) x11() # 4 variables mosaicplot(~ Hair+Eye+Sex+Opinion, data=toy.mosaics, color = TRUE) x11() # 5 variables (where is label name Race?) mosaicplot(~ Hair+Eye+Sex+Opinion+Race, data=toy.mosaics, color = TRUE) x11() # 6 variables (where are label name Race and Age?) mosaicplot(~ Hair+Eye+Sex+Opinion+Race+Age, data=toy.mosaics, color = TRUE) I think I am wrong to put a model or something wrong in mosaicplot? I was wondering if someone can help me. Kindly regards, Muhammad Subianto > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor1.0 year 2005 month04 day 18 language R > packageDescription("vcd") Package: vcd Version: 0.1-3.5 Date: 2005-02-28 Title: Visualizing Categorical Data Author: David Meyer, Achim Zeileis, Alexandros Karatzoglou, Kurt Hornik Maintainer: Kurt Hornik <[EMAIL PROTECTED]> Description: Functions and data sets based on the book "Visualizing Categorical Data" by Michael Friendly. License: GPL Depends: R (>= 1.4.0), MASS Packaged: Mon Feb 28 21:02:02 2005; hornik Built: R 2.1.0; ; 2005-04-09 21:52:15; windows __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to change all name of variables
Dear R-helpers, First I apologize if my question is quite simple I have a large datasets which more 100 variables. For a research I need to change all name of variables with add one or more letters on each variables. For example, > data(Pima.tr) > Pima.tr[1:5,] npreg glu bp skin bmi ped age type 1 5 86 68 28 30.2 0.364 24 No 2 7 195 70 33 25.1 0.163 55 Yes 3 5 77 82 41 35.8 0.156 35 No 4 0 165 76 43 47.9 0.259 26 No 5 0 107 60 25 26.4 0.133 23 No > > dimnames(Pima.tr)[[2]] [1] "npreg" "glu" "bp""skin" "bmi" "ped" "age" "type" > I need to change the variables name , "npreg" "glu" "bp" "skin" "bmi" "ped" "age" "type" with "xyz.npreg" "xyz.glu" "xyz.bp" "xyz.skin" "xyz.bmi" "xyz.ped" "xyz.age" "xyz.type" How can I make this (automatically). I don't want to make manual with more 100 variables. I would be very happy if anyone could help me. Thank you for your time. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to change all name of variables
Dear all R-helpers, Thanks you very much for your help. I would like to thanks Sean Davis and Gabor Grothendieck for their help. Best wishes, Muhammad Subianto On this day 6/2/2005 3:21 PM, Gabor Grothendieck wrote: > > Try this: > > names(prima) <- paste("xyz", names(prima), sep = ".") > On this day 6/2/2005 1:20 PM, Sean Davis wrote: > See ?paste. > > Something like below if you have 100 column names: > > dimnames(pima.tr)[[2]] <- > paste(rep('xyz',100),dimnames(pima.tr)[[2]],sep=".") > > You probably want to test the paste statement before setting the > dimnames, or operate on a copy of the data until you get the hang of > using paste. > > Sean On this day 6/2/2005 1:04 PM, Muhammad Subianto wrote: Dear R-helpers, First I apologize if my question is quite simple I have a large datasets which more 100 variables. For a research I need to change all name of variables with add one or more letters on each variables. For example, > data(Pima.tr) > Pima.tr[1:5,] npreg glu bp skin bmi ped age type 1 5 86 68 28 30.2 0.364 24 No 2 7 195 70 33 25.1 0.163 55 Yes 3 5 77 82 41 35.8 0.156 35 No 4 0 165 76 43 47.9 0.259 26 No 5 0 107 60 25 26.4 0.133 23 No > > dimnames(Pima.tr)[[2]] [1] "npreg" "glu" "bp""skin" "bmi" "ped" "age" "type" > I need to change the variables name , "npreg" "glu" "bp" "skin" "bmi" "ped" "age" "type" with "xyz.npreg" "xyz.glu" "xyz.bp" "xyz.skin" "xyz.bmi" "xyz.ped" "xyz.age" "xyz.type" How can I make this (automatically). I don't want to make manual with more 100 variables. I would be very happy if anyone could help me. Thank you for your time. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] adaboost more two classes
Dear R-Helper, I want to know, is there any function/package can handle adaboost more two classes? I know packages gbm and boost, but there are only for 2 classes (correct me if I mistake). Regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] data.frame to character
Hi, Excuse me for this simple question. How to convert as.data.frame to as.character? ?data.frame > L3 <- LETTERS[1:3] > L10 <- LETTERS[1:10] > d <- data.frame(cbind(x=c("XYZ"), y=L10), fac=sample(L3, 10, repl=TRUE)) > d x y fac 1 XYZ A A 2 XYZ B A 3 XYZ C A 4 XYZ D A 5 XYZ E B 6 XYZ F C 7 XYZ G A 8 XYZ H C 9 XYZ I B 10 XYZ J A > str(d) `data.frame': 10 obs. of 3 variables: $ x : Factor w/ 1 level "XYZ": 1 1 1 1 1 1 1 1 1 1 $ y : Factor w/ 10 levels "A","B","C","D",..: 1 2 3 4 5 6 7 8 9 10 $ fac: Factor w/ 3 levels "A","B","C": 1 1 1 1 2 3 1 3 2 1 > d[3,] x y fac 3 XYZ C A > > as.character(d[3,]) [1] "1" "3" "1" > I think as.character the result something like [3] "XYZ" "C" "A" I don't know how to convert it. Any help gratefully received. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] data.frame to character - thanks
Dear all, Thank you very much for your help. I would like to thank Andy Liaw and Gabor Grothendieck for their fast help. Regards, Muhammad Subianto On this day 6/10/2005 2:30 PM, Liaw, Andy wrote: > Is this what you want? > > >>d[] <- lapply(d, as.character) >>str(d) > > `data.frame': 10 obs. of 3 variables: > $ x : chr "XYZ" "XYZ" "XYZ" "XYZ" ... > $ y : chr "A" "B" "C" "D" ... > $ fac: chr "B" "A" "C" "B" ... > > Andy On this day 6/10/2005 2:35 PM, Gabor Grothendieck wrote: > On 6/10/05, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > >>Hi, >>Excuse me for this simple question. >>How to convert as.data.frame to as.character? >> >> ?data.frame >> >> > L3 <- LETTERS[1:3] >> > L10 <- LETTERS[1:10] >> > d <- data.frame(cbind(x=c("XYZ"), y=L10), fac=sample(L3, 10, repl=TRUE)) > > > > d[] <- as.matrix(d) > On this day 6/10/2005 2:23 PM, Muhammad Subianto wrote: > Hi, > Excuse me for this simple question. > How to convert as.data.frame to as.character? > > ?data.frame > > > L3 <- LETTERS[1:3] > > L10 <- LETTERS[1:10] > > d <- data.frame(cbind(x=c("XYZ"), y=L10), fac=sample(L3, 10, repl=TRUE)) > > d > x y fac > 1 XYZ A A > 2 XYZ B A > 3 XYZ C A > 4 XYZ D A > 5 XYZ E B > 6 XYZ F C > 7 XYZ G A > 8 XYZ H C > 9 XYZ I B > 10 XYZ J A > > str(d) > `data.frame': 10 obs. of 3 variables: > $ x : Factor w/ 1 level "XYZ": 1 1 1 1 1 1 1 1 1 1 > $ y : Factor w/ 10 levels "A","B","C","D",..: 1 2 3 4 5 6 7 8 9 10 > $ fac: Factor w/ 3 levels "A","B","C": 1 1 1 1 2 3 1 3 2 1 > > d[3,] > x y fac > 3 XYZ C A > > > > as.character(d[3,]) > [1] "1" "3" "1" > > > > I think as.character the result something like > [3] "XYZ" "C" "A" > > I don't know how to convert it. > Any help gratefully received. > Thank you very much in advance. > Kindly regards, > Muhammad Subianto > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] combination which limited
Dear R-helpers, I am learning about combination in R. I want to combination all of possible variable but it limited. I am sorry I could not explain exactly. For usefull I give an example interface <- c("usb","fireware","infra","bluetooth") screen<- c("lcd","cube") computer <- c("pc","server","laptop") available <- c("yes","no") What the result I need, something like this below, usb lcd pc yes fireware lcd pc yes infralcd pc yes bluetoothlcd pc yes usb cubepc yes usb lcd server yes usb lcd laptop yes usb lcd pc no How can I do that? I was wondering if someone can help me. Thanks you for your time and best regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] combination which limited
Dear All, Many thanks to Marc Schwartz and Gabor Grothendieck who have explained me about using expand.grid function and clearly explain how to use JGR. > dd <- expand.grid(interface = interface, screen = screen, >computer = computer, available = available) > > There are several possibilities now: > > 1. you could list out dd on the console and note the number of the > rows you want to keep: > > idx <- c(1,5,7) > dd2 <- dd[,idx] > I like a possible no. 1, because I can use and explore with my hand, > idx <- c(1:5,9,17,25) > dd2 <- dd[idx,] > dd2 interface screen computer available 1usblcd pc yes 2 firewarelcd pc yes 3 infralcd pc yes 4 bluetoothlcd pc yes 5usb cube pc yes 9usblcd server yes 17 usblcd laptop yes 25 usblcd pcno > Regards, Muhammad Subianto Notepad, Copy and Paste are my best friend to use R.2.1.0 on windows 2000 On 6/11/05, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On 6/11/05, Marc Schwartz <[EMAIL PROTECTED]> wrote: > > On Sat, 2005-06-11 at 20:44 +0200, Muhammad Subianto wrote: > > > Dear R-helpers, > > > I am learning about combination in R. > > > I want to combination all of > > > possible variable but it limited. > > > I am sorry I could not explain exactly. > > > For usefull I give an example > > > interface <- c("usb","fireware","infra","bluetooth") > > > screen<- c("lcd","cube") > > > computer <- c("pc","server","laptop") > > > available <- c("yes","no") > > > > > > What the result I need, something like this below, > > > usb lcd pc yes > > > fireware lcd pc yes > > > infralcd pc yes > > > bluetoothlcd pc yes > > > usb cubepc yes > > > usb lcd server yes > > > usb lcd laptop yes > > > usb lcd pc no > > > > > > How can I do that? > > > I was wondering if someone can help me. > > > Thanks you for your time and best regards, > > > Muhammad Subianto > > > > Use: > > > > > expand.grid(interface, screen, computer, available) > >Var1 Var2 Var3 Var4 > > 1usb lcd pc yes > > 2 fireware lcd pc yes > > 3 infra lcd pc yes > > 4 bluetooth lcd pc yes > > 5usb cube pc yes > > 6 fireware cube pc yes > > 7 infra cube pc yes > > 8 bluetooth cube pc yes > > 9usb lcd server yes > > 10 fireware lcd server yes > > 11 infra lcd server yes > > 12 bluetooth lcd server yes > > 13 usb cube server yes > > 14 fireware cube server yes > > 15 infra cube server yes > > 16 bluetooth cube server yes > > 17 usb lcd laptop yes > > 18 fireware lcd laptop yes > > 19 infra lcd laptop yes > > 20 bluetooth lcd laptop yes > > 21 usb cube laptop yes > > 22 fireware cube laptop yes > > 23 infra cube laptop yes > > 24 bluetooth cube laptop yes > > 25 usb lcd pc no > > 26 fireware lcd pc no > > 27 infra lcd pc no > > 28 bluetooth lcd pc no > > 29 usb cube pc no > > 30 fireware cube pc no > > 31 infra cube pc no > > 32 bluetooth cube pc no > > 33 usb lcd server no > > 34 fireware lcd server no > > 35 infra lcd server no > > 36 bluetooth lcd server no > > 37 usb cube server no > > 38 fireware cube server no > > 39 infra cube server no > > 40 bluetooth cube server no > > 41 usb lcd laptop no > > 42 fireware lcd laptop no > > 43 infra lcd laptop no > > 44 bluetooth lcd laptop no > > 45 usb cube laptop no > > 46 fireware cube laptop no > > 47 infra cube laptop no > > 48 bluetooth cube laptop no > > > > > > See ?expand.grid for more information. > > > > > After you do the above you will still want to cut it down to just > the rows you need. > > As expained, use expand.grid. Let's assume you used this statement: > > dd <- expand.grid(interface = interface, screen = screen, >computer = comp
Re: [R] combination which limited
Dear R-helpers, On this day 6/12/2005 10:48 AM, Muhammad Subianto wrote: > Dear All, > Many thanks to Marc Schwartz and Gabor Grothendieck who have explained > me about using expand.grid function and clearly explain how to use > JGR. > > >>dd <- expand.grid(interface = interface, screen = screen, >> computer = computer, available = available) >> >>There are several possibilities now: >> >>1. you could list out dd on the console and note the number of the >>rows you want to keep: >> >>idx <- c(1,5,7) >>dd2 <- dd[,idx] >> > > > I like a possible no. 1, because I can use and explore with my hand, > >> idx <- c(1:5,9,17,25) >> dd2 <- dd[idx,] >> dd2 > >interface screen computer available > 1usblcd pc yes > 2 firewarelcd pc yes > 3 infralcd pc yes > 4 bluetoothlcd pc yes > 5usb cube pc yes > 9 usblcd server yes > 17 usblcd laptop yes > 25 usblcd pcno > > > Regards, > Muhammad Subianto > Notepad, Copy and Paste are my best friend to use R.2.1.0 on windows 2000 > As previous mail, using expand.grid can handle all variables in datasets. But, if I need only one or more combinations I can choice combination (rows) which I need, interface <- c("usb","fireware","infra","bluetooth") screen<- c("lcd","cube") computer <- c("pc","server","laptop") available <- c("yes","no") dd <- expand.grid(interface=interface,screen=screen,computer=computer,available=available) idx <- c(1:5,9,17,25) # this combination rows) what I need dd2 <- dd[idx,] dd2 Because I only need combination (1,2,3,4,5,9,17 and 25), I tried to make a simple code to make sure what pattern the combination I have. I was wondering if someone can help me to make a simple function. smdxc <- rbind( c(levels(dd[,1])[1], #combination 1 levels(dd[,2])[1], levels(dd[,3])[1], levels(dd[,4])[1]), c(levels(dd[,1])[2], #combination 2 levels(dd[,2])[1], levels(dd[,3])[1], levels(dd[,4])[1]), c(levels(dd[,1])[3], #combination 3 levels(dd[,2])[1], levels(dd[,3])[1], levels(dd[,4])[1]), c(levels(dd[,1])[4], #combination 4 levels(dd[,2])[1], levels(dd[,3])[1], levels(dd[,4])[1]), c(levels(dd[,1])[1], #combination 5 levels(dd[,2])[2], levels(dd[,3])[1], levels(dd[,4])[1]), c(levels(dd[,1])[1], #combination 9 levels(dd[,2])[1], levels(dd[,3])[2], levels(dd[,4])[1]), c(levels(dd[,1])[1], #combination 17 levels(dd[,2])[1], levels(dd[,3])[3], levels(dd[,4])[1]), c(levels(dd[,1])[1], #combination 25 levels(dd[,2])[1], levels(dd[,3])[1], levels(dd[,4])[2])) smdxc # the result = dd2 Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] combination which limited - thanks again
Dear all, Again, I would like to thank Gabor Grothendieck for your help. I can improve which you suggest with the others combination. And thank you for your time. Sincerely, Muhammad Subianto On this day 6/13/2005 2:38 PM, Gabor Grothendieck wrote: > > The pattern seems to be that each row contains at most one column > that is not at level 1. That is the entry at row i and column col[i] has > level lev[i] and all other entries are at level 1. > > col <- c(1,1,1,1,2,3,3,4) > lev <- c(1:4,2,2,3,2) > mat <- matrix(1, length(col), 4) > mat[cbind(seq(col),col)] <- lev > data.frame(interface = factor(mat[,1], lab = interface), > screen = factor(mat[,2], lab = screen), > computer = factor(mat[,3], lab = computer), > available = factor(mat[,4], lab = available)) > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] update.packages() - gregmisc
Dear all, I have a problem to update package gregmisc. After I update, > update.packages(ask='graphics') trying URL 'http://cran.at.r-project.org/bin/windows/contrib/2.1/gregmisc_2.0.8.zip' Content type 'application/zip' length 2465 bytes opened URL downloaded 2465 bytes package 'gregmisc' successfully unpacked and MD5 sums checked ... then try to update again, still I must update package gregmisc, etc. I have tried 3,4,5, times with the same result. Best, Muhammad Subianto > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor1.0 year 2005 month04 day 18 language R > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] update.packages() - gregmisc
Thanks. I do like this, > remove.packages("gregmisc", .libPaths()[1]) > remove.packages("gtools", .libPaths()[1]) > install.packages("gregmisc", .libPaths()[1]) > update.packages() > update.packages() > install.packages("gtools", .libPaths()[1]) > update.packages() > update.packages() > update.packages(ask='graphics') Regards, Muhammad Subianto R.2.1.0 on W2K On this day 6/14/2005 1:51 PM, Gabor Grothendieck wrote: > On 6/14/05, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > >>Dear all, >>I have a problem to update package gregmisc. >>After I update, >> > update.packages(ask='graphics') >>trying URL >>'http://cran.at.r-project.org/bin/windows/contrib/2.1/gregmisc_2.0.8.zip' >>Content type 'application/zip' length 2465 bytes >>opened URL >>downloaded 2465 bytes >> >>package 'gregmisc' successfully unpacked and MD5 sums checked >>... >> >>then try to update again, still I must update package gregmisc, etc. >>I have tried 3,4,5, times with the same result. >> > > > This was discussed on r-devel recently. See: > > https://www.stat.math.ethz.ch/pipermail/r-devel/2005-June/033479.html > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] update.packages() - gregmisc
On this day 6/15/2005 12:03 AM, Gabor Grothendieck wrote: > Is the code in your post intended to show what worked so others > will know what to do Yes, I succes to remove and install gregmisc again like I have posted before. Regards, Muhammad Subianto or is that code intended to show what you > did but did not work? > > If its the latter, I successfully did it last week and don't > clearly remember my precise steps but I may have done this: > > R CMD remove gdata > R CMD remove gmodels > R CMD remove gplots > R CMD remove gtools > R CMD remove gregmisc > > I assume that using remove.packages, viz. > > remove.packages("gregmisc") > etc. > > would have given the same result. > > > On 6/14/05, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > >>Thanks. >>I do like this, >> > remove.packages("gregmisc", .libPaths()[1]) >> > remove.packages("gtools", .libPaths()[1]) >> > install.packages("gregmisc", .libPaths()[1]) >> > update.packages() >> > update.packages() >> > install.packages("gtools", .libPaths()[1]) >> > update.packages() >> > update.packages() >> > update.packages(ask='graphics') >> >>Regards, >>Muhammad Subianto >>R.2.1.0 on W2K >> >>On this day 6/14/2005 1:51 PM, Gabor Grothendieck wrote: >> >>>On 6/14/05, Muhammad Subianto <[EMAIL PROTECTED]> wrote: >>> >>> >>>>Dear all, >>>>I have a problem to update package gregmisc. >>>>After I update, >>>> >>>>>update.packages(ask='graphics') >>>> >>>>trying URL >>>>'http://cran.at.r-project.org/bin/windows/contrib/2.1/gregmisc_2.0.8.zip' >>>>Content type 'application/zip' length 2465 bytes >>>>opened URL >>>>downloaded 2465 bytes >>>> >>>>package 'gregmisc' successfully unpacked and MD5 sums checked >>>>... >>>> >>>>then try to update again, still I must update package gregmisc, etc. >>>>I have tried 3,4,5, times with the same result. >>>> >>> >>> >>>This was discussed on r-devel recently. See: >>> >>>https://www.stat.math.ethz.ch/pipermail/r-devel/2005-June/033479.html > > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] how to change automatically 0=no and 1=yes
Dear R-helpers, I have dataset (data.frame) like below, x1 x2 x3 x4 x5 x6 x7 x8 x9 ... x1200 000110011 100110011 010110011 110110011 ... How can I change automatically 0=no and 1=yes. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to change automatically 0=no and 1=yes
Dear all, Sean Davis, Dimitris Rizopoulos and Marc Schwartz, thanks for your great help. It works perfectly. Thanks a lot. All the best, Muhammad Subianto On this day 6/15/2005 4:06 PM, Sean Davis wrote: > > x <- data.frame(matrix(c(1,0,1,0,1,1),nrow=3)) > > x[x==0] <- 'no' > > x[x==1] <- 'yes' > > x > X1 X2 > 1 yes no > 2 no yes > 3 yes yes > On this day 6/15/2005 4:06 PM, Dimitris Rizopoulos wrote: > try this: > > dat <- data.frame(matrix(sample(0:1, 100 * 20, TRUE), 100, 20)) > > dat[] <- lapply(dat, factor, levels = c(0, 1), labels = c("no", > "yes")) > dat > On this day 6/15/2005 4:16 PM, Marc Schwartz wrote: > > >>as.data.frame(ifelse(df == 0, "No", "Yes")) > On this day 6/15/2005 3:58 PM, Muhammad Subianto wrote: > Dear R-helpers, > I have dataset (data.frame) like below, >x1 x2 x3 x4 x5 x6 x7 x8 x9 ... x1200 > 000110011 > 100110011 > 01011001 1 > 110110011 > ... > How can I change automatically 0=no and 1=yes. > > Thank you very much in advance. > Kindly regards, > Muhammad Subianto > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] CORRELATION MATRIX CONVERSION
Maybe like: > dat X Y Z X 1.0 0.9 0.5 Y 0.9 1.0 0.1 Z 0.5 0.1 1.0 > datrow <- stack(as.data.frame(dat)) > datrow$X=rownames(dat) > datrow values ind X 11.0 X X 20.9 X Y 30.5 X Z 40.9 Y X 51.0 Y Y 60.1 Y Z 70.5 Z X 80.1 Z Y 91.0 Z Z > Regards, Muhammad Subianto On this day 6/17/2005 8:14 AM, Omer Bakkalbasi wrote: > How do I convert the output of cor(x) to a columnar format? > Ex. from format below > XYZ > X 1.0 0.9 0.5 > Y 0.9 1.0 0.1 > Z 0.5 0.1 1.0 > > to format below > > X X 1.0 > X Y 0.9 > X Z 0.5 > Y X 0.9 > Y Y 1.0 > Y Z 0.1 > Z X 0.5 > Z Y 0.1 > Z Z 1.0 > > Thanks! > > Omer > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] convert data
Dear R-helper, I have a data set like: OLDa ALL OLDc OLDa OLDb NEW OLDb OLDa ALL . . . ALL OLDc NEW I want to convert that data as OLDa=1, OLDb=2, OLDc=3, NEW=4 and ALL=5 or the result like: 1 5 3 1 2 4 2 1 5 . . . 5 3 4 How can I do it. Thanks you for your help. Best regards, Muhammad Subianto __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Change the result data
Dear R-helper, I have a data like: > hec.data <-array(c(5,15,20,68,29,54,84,119,14,14,17,26,16,10,94,7), +dim=c(4,4), +dimnames=list(eye=c("Green","Hazel", "Blue", "Brown"), +hair=c("Black", "Brown", "Red", "Blond"))) > hec.data hair eye Black Brown Red Blond Green 529 1416 Hazel1554 1410 Blue 2084 1794 Brown68 119 26 7 > but I want the result like below.: hair eye counts Black Green5 Black Hazel 15 Black Blue 20 Black Brown 68 Brown Green 29 Brown Hazel 54 Brown Blue 84 Brown Brown 119 Red Green 14 Red Hazel 14 Red Blue 17 Red Brown 26 Blond Green 16 Blond Hazel 10 Blond Blue 94 Blond Brown7 How can I do it. Thanks you for your help. Best regards, Muhammad Subianto __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Change the result data (thanks you)
Dear R-helper, I use like this below (from Prof. Peter Dalgaard) and thanks to other R-helper for your help. Best regard, Muhammad Subianto as.data.frame(as.table(hec.data)) eye hair Freq 1 Green Black5 2 Hazel Black 15 3 Blue Black 20 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to make two figures in one plot - package vcd
Dear all, I have a problem to make figures with two columns in package vcd. Here an example code I take from "\library\vcd\html\plot.loglm.html" What I need, I want to make two figures in one plot. How could I do that. I have tried with layout(rbind(c(1, 1, 2, 2))) but the same result, two plot. Best wishes, Muhammad Subianto library(vcd) oldpar <- par(mfrow=c(1, 2)) ## mosaic display for PreSex model data(PreSex) fm <- loglm(~ PremaritalSex * ExtramaritalSex * (Gender + MaritalStatus), data = aperm(PreSex, c(3, 2, 4, 1))) ## visualize Pearson statistic plot(fm, split_vertical = TRUE) ## visualize LR statistic plot(fm, split_vertical = TRUE, residuals_type = "deviance") par(oldpar) > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor1.1 year 2005 month06 day 20 language R > > packageDescription("vcd") Package: vcd Version: 0.9-3 Date: 2005-09-01 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to make two figures in one plot - package vcd
On this day 16/09/2005 05:59 PM, Dieter Menne wrote: > Muhammad Subianto gmail.com> writes: > > >>I have a problem to make figures with two columns in package vcd. >>Here an example code I take from "\library\vcd\html\plot.loglm.html" >>What I need, I want to make two figures in one plot. >> >>library(vcd) >>oldpar <- par(mfrow=c(1, 2)) >>## mosaic display for PreSex model >>data(PreSex) >>fm <- loglm(~ PremaritalSex * ExtramaritalSex * (Gender + MaritalStatus), >> data = aperm(PreSex, c(3, 2, 4, 1))) >>## visualize Pearson statistic >>plot(fm, split_vertical = TRUE) >>## visualize LR statistic >>plot(fm, split_vertical = TRUE, residuals_type = "deviance") >>par(oldpar) > > .. > > The example worked in the previous version, but David Meyer has rewritten the > whole package using grid functions. Figures are much nicer now, but > documentations is a bit on the sparse side. I don't have the docs at hand > currently, but I believe you should looks at strucplot to set the layout > there, > or use grid directly. > Thanks you for your respon. Yes, I know this a new version vcd (mosaic->vcd <> mosaicplot->core,base R). This version is look very nice. I am very happy to use this version. I have tried to look at documentations like "\library\vcd\html\strucplot.html" I have used "newpage=FALSE" but it didn't change. I will try to look at grid package. > Greetings from an Ex-Cirebonese > > Dieter Best, Muhammad Subianto PS. Ex-Cirebonese? Ha ha ha ... I know this ... http://en.wikipedia.org/wiki/Cirebon how about this http://en.wikipedia.org/wiki/Banda_Aceh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] make some possible neighbourhoods
Dear all, I want to make some possible neighbourhoods in dataset below, V1 <- c(0,1,2,3) V2 <- c(0,1) V3 <- c(0,1,2) V4 <- c(0,1,2,3,4) and then I have a domain which the number of each variables. For dataset above a domain, domains <- c(3,1,2,4) To create the neighbourhoods I choice one point from all possible point in dataset. I take one random point, for instance: point <- c(2,1,0,0) To produce the neighbourhoods I run like this (see a code below): neighb2(point,domains) > neighb2(point,domains) Error: subscript out of bounds > Try one random point again, point2 <- c(2,0,1,3) neighb2(point2,domains) > neighb2(point2,domains) Error: subscript out of bounds > but if I choice a random point, > point1 <- c(0,1,1,0) > neighb2(point1,domains) [,1] [,2] [,3] [,4] [1,]1010 [2,]1210 [3,]1310 [4,]2010 [5,]2210 ... [65,]0133 [66,]0143 [67,]0104 [68,]0124 [69,]0134 [70,]0144 > it's OK. I am not sure where I am mistake. I believe it is the problem of the code. How should I fix this problem. Thanks in advance for any help. Best regards, Muhammad Subianto Here is a code: neighb2 <- function(point,domains) { nn2 <- sum(domains)*(sum(domains)-1) nvar <- length(point) neighb <- matrix(nrow=nn2,ncol=nvar) k <- 1 for (i in 1:nvar) { restvars <- 1:nvar restvars <- restvars[-i] for (j in restvars) { values1 <- values2 <- 0:domains[i] values1 <- values1[-(point[i]+1)] values2 <- values2[-(point[j]+1)] for (m in values1) { for (n in values2) { neigh <- point neigh[i] <- m neigh[j] <- n neighb[k,] <- neigh k <- k+1 } } } } unique(neighb) } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] expand.grid problem
Hi all, I want to make all possible combination from dataset below: V1 <- c(0,1,2) V2 <- c(0,1) V3 <- c(0,1) V4 <- c(0,1) V5 <- c(0,1) V6 <- c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) V7 <- c(0,1,2,3,4,5,6) V8 <- c(0,1) V9 <- c(0,1) V10 <- c(0,1) V11 <- c(0,1) V12 <- c(0,1) V13 <- c(0,1) V14 <- c(0,1) V15 <- c(0,1,2,3,4,5,6,7,8,9) V16 <- c(0,1,2,3,4,5,6) V17 <- c(0,1,2,3,4,5,6,7,8) V18 <- c(0,1,2,3,4,5) V19 <- c(0,1) V20 <- c(0,1,2,3,4,5,6,7) When run expand.grid I found a problem: > all.V <- expand.grid(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20) Error in rep.int(rep.int(x, rep.int(rep.fac, nx)), orep) : invalid number of copies in rep() In addition: Warning message: NAs introduced by coercion > Then I try to reduce: > all.V.miss <- expand.grid(V1,V2,V3,V4,V5,V7,V8,V9,V10,V11,V17,V18,V19,V20) Error: cannot allocate vector of size 36288 Kb > What is that? Is this about memory or I must run on machine 64bit? Regards, Muhammad Subianto P4 2.0GHz 512MB RAM > R.version$platform [1] "i686-redhat-linux-gnu" > R.version$major [1] "2" > R.version$minor [1] "1.1" > R.version$year [1] "2005" > R.version$month [1] "06" > R.version$language [1] "R" __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] expand.grid problem
Dear all, Martyn Plummer and Jim Holtman (offlist) thanks you for quick respons. Now I understand. I need more machine and memory. Thanks a lot. Muhammad Subianto --- 20 columns and 54 billion rows? O:-) On this day 13/10/2005 01:45 PM, Martyn Plummer wrote: > > > It's all about memory. In your first example, you are trying to create > a data frame with 20 columns and 54 billion (thousand million) rows. > Just to store this amount of data as an array of doubles you would need > 8 terabytes of memory. You are being a bit optimistic trying to do it > with only 500 Megabytes. > > Martyn > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] a max value for each column
Dear R-list I have a dataset like below (points), how can I produce a max value for each column. I need a result like (I hope my eye correct): [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [1,] 211 10 99 14 19695 8 5 7 This is a small dataset from 1 row. > points [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [1,] 2109 161 11525 8 2 5 [2,] 191 10 9370041 6 5 1 [3,] 1304 3057115 6 3 6 [4,]519 616 19295 1 1 6 [5,]211 991 18132 8 1 2 [6,]705 45 144651 6 5 6 [7,]006 89 143203 7 2 6 [8,] 1501 30 14 17323 3 3 5 [9,] 1405 288 10165 2 3 6 [10,] 1214 6562414 4 4 7 [11,] 14113 12 10574 3 3 4 [12,] 1501 5577153 7 0 2 [13,] 140547 11204 2 2 3 [14,] 1306 9462493 4 0 3 [15,] 2115 79 14 14635 6 5 6 > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] a max value for each column
Acchhh very easy, time to drink a cup of coffe, but Thank you for your all. apply(points, 2, max) Best regards, Muhammad Subianto On this day 17/10/2005 02:34 PM, Muhammad Subianto wrote: > Dear R-list > > I have a dataset like below (points), how can I produce a max value for > each column. I need a result like (I hope my eye correct): > >[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] > [1,] 211 10 99 14 19695 8 5 7 > > This is a small dataset from 1 row. > > points >[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] > [1,] 2109 161 11525 8 2 5 > [2,] 191 10 9370041 6 5 1 > [3,] 1304 3057115 6 3 6 > [4,]519 616 19295 1 1 6 > [5,]211 991 18132 8 1 2 > [6,]705 45 144651 6 5 6 > [7,]006 89 143203 7 2 6 > [8,] 1501 30 14 17323 3 3 5 > [9,] 1405 288 10165 2 3 6 > [10,] 1214 6562414 4 4 7 > [11,] 14113 12 10574 3 3 4 > [12,] 1501 5577153 7 0 2 > [13,] 140547 11204 2 2 3 > [14,] 1306 9462493 4 0 3 > [15,] 2115 79 14 14635 6 5 6 > > > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] error open .RData
Dear R-list, I have a problem to open my R workspace. When I try to open my file .Rdata with double-clik on windows explore I get the error like this: Error in load(name, envir = .GlobalEnv) : error reading from connection and on windows error: Fatal error: unable to restore saved data in .RData I try with, > load("CaseStudyHouseID50.RData", .GlobalEnv) Error in load("CaseStudyHouseID50.RData", .GlobalEnv) : error reading from connection > > load("CaseStudyHouseID50.RData") Error in load("CaseStudyHouseID50.RData") : error reading from connection > I have done to save my R workspace like this: save(list = ls(all=TRUE), file = "CaseStudyHouseID50.RData") #### What is wrong? Is there anyway to open .RData? Regards, Muhammad Subianto > R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.0 year 2005 month10 day 06 svn rev 35749 language R > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] error open .RData
> Your .Rdata file is probably corrupted. I will investigate. Thanks for you info. Because of my file .RData very large about 75MB. Best wishes, Muhammad Subianto On this day 19/10/2005 12:21 PM, Petr Pikal wrote: > Hi > > Your .Rdata file is probably corrupted. Unless you have a working > copy of it elsewhere or sources of your data together with history > of your commands you are probably in deep trouble .Rdata is a > binary format and it is not recommended to safe and reliable saving > of your work as you have only limited, if any, possibilities to > recover it if anything goes wrong. > > I usually have all my important source data in txt or xls format and > I frequently save history in separate files (on daily basis or > sometimes several times a day) to be able to repeat everything I > have done. > > Cheers > Petr > > > On 19 Oct 2005 at 11:58, Muhammad Subianto wrote: > > Date sent: Wed, 19 Oct 2005 11:58:11 +0200 > From: Muhammad Subianto <[EMAIL PROTECTED]> > To: r-help@stat.math.ethz.ch > Subject: [R] error open .RData > > >>Dear R-list, >>I have a problem to open my R workspace. >>When I try to open my file .Rdata with double-clik on windows explore >>I get the error like this: >> >>Error in load(name, envir = .GlobalEnv) : error reading from >>connection >> >>and on windows error: >> >>Fatal error: unable to restore saved data in .RData >> >>I try with, >> >> > load("CaseStudyHouseID50.RData", .GlobalEnv) >>Error in load("CaseStudyHouseID50.RData", .GlobalEnv) : >> error reading from connection >> > >> >> > load("CaseStudyHouseID50.RData") >>Error in load("CaseStudyHouseID50.RData") : >> error reading from connection >> > >> >>I have done to save my R workspace like this: >>###### >>## >> save(list = ls(all=TRUE), >>file = "CaseStudyHouseID50.RData") >>## >>## >> >>What is wrong? >>Is there anyway to open .RData? >> >>Regards, Muhammad Subianto >> >> > R.version >> _ >>platform i386-pc-mingw32 >>arch i386 >>os mingw32 >>system i386, mingw32 >>status >>major2 >>minor2.0 >>year 2005 >>month10 >>day 06 >>svn rev 35749 >>language R >> > >> >>__ >>R-help@stat.math.ethz.ch mailing list >>https://stat.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide! >>http://www.R-project.org/posting-guide.html > > > Petr Pikal > [EMAIL PROTECTED] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] search a value in variables dataset
Dear R-list, I have a dataset, say (the real dataset is 20 columns,110200 rows). > my.reducedID V1 V2 V3 V4 V5 V6 V7 V8 V9 [1,] 1 0 0 1 14 3 1 0 2 [2,] 2 0 0 1 14 3 1 0 2 [3,] 0 1 0 1 14 2 1 0 2 [4,] 0 0 1 1 14 3 1 0 2 [5,] 0 1 1 0 14 2 1 0 2 [6,] 0 0 0 1 14 3 1 0 2 [7,] 0 0 0 1 0 3 1 0 2 [8,] 0 0 0 1 1 3 1 0 2 [9,] 0 0 0 1 2 3 1 0 2 [10,] 0 0 0 1 3 3 1 0 2 [11,] 0 0 0 1 4 3 1 0 2 [12,] 0 0 0 1 5 3 1 0 2 [13,] 0 0 0 1 6 3 1 0 2 [14,] 0 0 0 1 7 3 1 0 2 [15,] 0 0 0 1 8 3 1 0 2 [16,] 0 0 0 1 9 3 1 0 2 [17,] 0 0 0 1 10 3 1 0 2 [18,] 0 0 0 1 11 3 1 0 2 [19,] 0 0 0 1 12 3 1 0 2 [20,] 0 0 0 1 13 3 1 0 2 [21,] 0 0 0 1 15 3 1 0 2 [22,] 0 0 0 1 16 3 1 0 2 [23,] 0 0 0 1 17 3 1 0 2 [24,] 0 0 0 1 18 3 1 0 2 [25,] 0 0 0 1 19 3 1 0 2 [26,] 0 0 0 1 20 3 1 0 2 [27,] 0 0 0 1 14 0 1 0 2 [28,] 0 0 0 1 14 1 1 0 2 [29,] 0 0 0 1 14 2 1 0 2 [30,] 0 0 0 1 14 4 1 0 2 > I want to search a value in variables, say V1=0, V5=14 and V6=2. The result should look like V1 V2 V3 V4 V5 V6 V7 V8 V9 [3,] 0 1 0 1 14 2 1 0 2 [5,] 0 1 1 0 14 2 1 0 2 [29,] 0 0 0 1 14 2 1 0 2 I can do this with: my.reducedID[c(3,5,29),] Because I have very large dataset I can not make this manual. Then I need the ID of row did not change, I mean like, [3,] [5,] [29,] In dataset this is about ID our customers. I was wondering if anyone give me a trick to make simple. Thanks you very much for any suggestions. Best, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] search a value in variables dataset
Dear All, Perfect. Thanks you very much for your help. Best, Muhammad Subianto >>my.reducedID<-read.table(file.choose()) >>head(my.reducedID) > > V1 V2 V3 V4 V5 V6 V7 V8 V9 >[1,] 1 0 0 1 14 3 1 0 2 >[2,] 2 0 0 1 14 3 1 0 2 >[3,] 0 1 0 1 14 2 1 0 2 >[4,] 0 0 1 1 14 3 1 0 2 >[5,] 0 1 1 0 14 2 1 0 2 >[6,] 0 0 0 1 14 3 1 0 2 > >>attach(my.reducedID) >>my.reducedID[(V1==0 & V5==14 & V6==2),] > > V1 V2 V3 V4 V5 V6 V7 V8 V9 >[3,] 0 1 0 1 14 2 1 0 2 >[5,] 0 1 1 0 14 2 1 0 2 >[29,] 0 0 0 1 14 2 1 0 2 > OR ## >my.reducedID[ my.reducedID[,1]==0 & my.reducedID[,5]==14 & >my.reducedID[,6]==2, ] > On this day 20/10/2005 03:59 PM, Muhammad Subianto wrote: > Dear R-list, > I have a dataset, say (the real dataset is 20 columns,110200 rows). > > > my.reducedID >V1 V2 V3 V4 V5 V6 V7 V8 V9 > [1,] 1 0 0 1 14 3 1 0 2 > [2,] 2 0 0 1 14 3 1 0 2 > [3,] 0 1 0 1 14 2 1 0 2 > [4,] 0 0 1 1 14 3 1 0 2 > [5,] 0 1 1 0 14 2 1 0 2 > [6,] 0 0 0 1 14 3 1 0 2 > [7,] 0 0 0 1 0 3 1 0 2 > [8,] 0 0 0 1 1 3 1 0 2 > [9,] 0 0 0 1 2 3 1 0 2 > [10,] 0 0 0 1 3 3 1 0 2 > [11,] 0 0 0 1 4 3 1 0 2 > [12,] 0 0 0 1 5 3 1 0 2 > [13,] 0 0 0 1 6 3 1 0 2 > [14,] 0 0 0 1 7 3 1 0 2 > [15,] 0 0 0 1 8 3 1 0 2 > [16,] 0 0 0 1 9 3 1 0 2 > [17,] 0 0 0 1 10 3 1 0 2 > [18,] 0 0 0 1 11 3 1 0 2 > [19,] 0 0 0 1 12 3 1 0 2 > [20,] 0 0 0 1 13 3 1 0 2 > [21,] 0 0 0 1 15 3 1 0 2 > [22,] 0 0 0 1 16 3 1 0 2 > [23,] 0 0 0 1 17 3 1 0 2 > [24,] 0 0 0 1 18 3 1 0 2 > [25,] 0 0 0 1 19 3 1 0 2 > [26,] 0 0 0 1 20 3 1 0 2 > [27,] 0 0 0 1 14 0 1 0 2 > [28,] 0 0 0 1 14 1 1 0 2 > [29,] 0 0 0 1 14 2 1 0 2 > [30,] 0 0 0 1 14 4 1 0 2 > > > > I want to search a value in variables, say V1=0, V5=14 and V6=2. > The result should look like >V1 V2 V3 V4 V5 V6 V7 V8 V9 > [3,] 0 1 0 1 14 2 1 0 2 > [5,] 0 1 1 0 14 2 1 0 2 > [29,] 0 0 0 1 14 2 1 0 2 > > I can do this with: my.reducedID[c(3,5,29),] > Because I have very large dataset I can not make this manual. > Then I need the ID of row did not change, I mean like, > [3,] > [5,] > [29,] > In dataset this is about ID our customers. > I was wondering if anyone give me a trick to make simple. > Thanks you very much for any suggestions. > > Best, Muhammad Subianto > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Take random sample from class variable
Dear all, Andy, thanks you for your help and suggestions. This is exactly what I was looking for. Kindly regards, Muhammad Subianto On 8/8/06, Liaw, Andy <[EMAIL PROTECTED]> wrote: > There may be better ways, but this should work: > > R> p.yes <- 0.7 > R> n.yes <- rbinom(1, nof.sample, p.yes) > R> n.no <- nof.sample - n.yes > R> dat.yes <- mydat[sample(which(mydat$Class == "yes"), n.yes, > replace=TRUE),] > R> dat.no <- mydat[sample(which(mydat$Class == "no"), n.no, replace=TRUE),] > > You can rbind() them, and shuffle the rows if you wish. > > Andy > > From: Muhammad Subianto > > > > Dear all, > > Suppose I have a dataset like below, then I take for example, > > 100 random sample "class" variable where contains "yes" and "no" > > respectively, 70% and 30%. > > I need a new 100 random sample from mydat dataset, but I > > can't get the result. > > Thanks you very much for any helps. > > Best, Muhammad Subianto > > > > mydat <- data.frame(size=c(30,12,15,10,12,12,25,30,20,14), > >A=c(0,1,0,1,0,1,1,1,0,0), > >B=c(1,1,0,1,0,1,1,0,0,1), > >C=c(0,0,1,1,0,0,1,1,0,0), > >D=c(1,1,1,1,0,1,0,0,1,1), > >E=c(1,1,0,1,1,1,1,1,1,0), > > > > Class=c("yes","yes","no","yes","yes","no","yes","no","yes","yes")) > > mydat > > # Maximal data from dataset > > max.size <- sum(mydat$size);max.size > > # I need sample random > > nof.sample <- 100 > > set.seed(123) > > sample.class <- sample(c("yes","no"), nof.sample, prob=c(.7, > > .3), replace=TRUE) sample.class sampledat.class <- > > mydat[sample.class,] sampledat.class > > > > __ > > R-help@stat.math.ethz.ch 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. > > > > > > > -- > Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch 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.
[R] How to compare rows of two matrices
Dear all, I have a dataset train <- cbind(c(0,2,2,1,0), c(8,9,4,0,2), 6:10, c(-1, 1, 1, -1, 1)) test <- cbind(1:5, c(0,1,5,1,3), c(1,1,2,0,3) ,c(1, 1, -1, 1, 1)) I want to find which rows of train and test it different in its last column (column 4). The solution must be something like train [,1] [,2] [,3] [,4] [1,]086 -1 [3,]2481 [4,]109 -1 test [,1] [,2] [,3] [,4] [1,]1011 [3,]352 -1 [4,]4101 I have tried with matrix(train %in% test, dim(train)) apply(train, 1, paste, collapse="") %in% apply(test, 1, paste, collapse="") It doesn't work. How can I do. Thanks for any help. Best, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
Re: [R] How to compare rows of two matrices
Dear Stephen C. Upton & Petr Pikal Thank you both very much for the suggestions! Best wishes, Muhammad Subianto On this day 24/08/2006 12:03, Muhammad Subianto wrote: > Dear all, > I have a dataset > train <- cbind(c(0,2,2,1,0), c(8,9,4,0,2), 6:10, c(-1, 1, 1, -1, 1)) > test <- cbind(1:5, c(0,1,5,1,3), c(1,1,2,0,3) ,c(1, 1, -1, 1, 1)) > > I want to find which rows of train and test it different in its last > column (column 4). > The solution must be something like > > train > [,1] [,2] [,3] [,4] > [1,]086 -1 > [3,]2481 > [4,]109 -1 > > > test > [,1] [,2] [,3] [,4] > [1,]1011 > [3,]352 -1 > [4,]4101 > > I have tried with > matrix(train %in% test, dim(train)) > apply(train, 1, paste, collapse="") %in% apply(test, 1, paste, > collapse="") > > It doesn't work. > How can I do. > Thanks for any help. > > Best, Muhammad Subianto > __ R-help@stat.math.ethz.ch 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.
[R] Check values in colums matrix
Dear all, I apologize if my question is quite simple. I have a dataset (20 columns & 1000 rows) which some of columns have the same value and the others have different values. Here are some piece of my dataset: obj <- cbind(c(1,1,1,4,0,0,1,4,-1), c(0,1,1,4,1,0,1,4,-1), c(1,1,1,4,2,0,1,4,-1), c(1,1,1,4,3,0,1,4,-1), c(1,1,1,4,6,0,1,5,-1), c(1,1,1,4,6,0,1,6,-1), c(1,1,1,4,6,0,1,7,-1), c(1,1,1,4,6,0,1,8,-1)) obj.tr <- t(obj) obj.tr > obj.tr [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,]11140014 -1 [2,]01141014 -1 [3,]11142014 -1 [4,]11143014 -1 [5,]11146015 -1 [6,]11146016 -1 [7,]11146017 -1 [8,]11146018 -1 > How can I do to check columns 2,3,4,6,7 and 9 have the same value, and columns 1,5 and 8 have different values. Best, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
Re: [R] Check values in colums matrix
Dear all, I would like to thank everybody who replied for their useful suggestions. Maybe, I am going through the book statistics to teach (fresh) myself. Wish you have a nice weekend. Regards, Muhammad Subianto On this day 24/08/2006 18:59, Muhammad Subianto wrote: > Dear all, > I apologize if my question is quite simple. > I have a dataset (20 columns & 1000 rows) which > some of columns have the same value and the others > have different values. > Here are some piece of my dataset: > obj <- cbind(c(1,1,1,4,0,0,1,4,-1), > c(0,1,1,4,1,0,1,4,-1), > c(1,1,1,4,2,0,1,4,-1), > c(1,1,1,4,3,0,1,4,-1), > c(1,1,1,4,6,0,1,5,-1), > c(1,1,1,4,6,0,1,6,-1), > c(1,1,1,4,6,0,1,7,-1), > c(1,1,1,4,6,0,1,8,-1)) > obj.tr <- t(obj) > obj.tr >> obj.tr > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] > [1,]11140014 -1 > [2,]01141014 -1 > [3,]11142014 -1 > [4,]11143014 -1 > [5,]11146015 -1 > [6,]11146016 -1 > [7,]11146017 -1 > [8,]11146018 -1 > > How can I do to check columns 2,3,4,6,7 and 9 have > the same value, and columns 1,5 and 8 have different values. > > Best, Muhammad Subianto > > __ > R-help@stat.math.ethz.ch 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. > __ R-help@stat.math.ethz.ch 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.
[R] Merge list to list - as matrix
Dear all, I have dataset x <- list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4)) y <- list(matrix(110:114, 5, 1),matrix(110:114, 5, 1),matrix(110:114, 5, 1)) I need merge x and y as list (y put in last column). The result is something like [[1]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 16 110 [2,]27 12 17 111 [3,]38 13 18 112 [4,]49 14 19 113 [5,]5 10 15 20 114 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 16 110 [2,]27 12 17 111 [3,]38 13 18 112 [4,]49 14 19 113 [5,]5 10 15 20 114 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 16 110 [2,]27 12 17 111 [3,]38 13 18 112 [4,]49 14 19 113 [5,]5 10 15 20 114 I have tried a <- list(x,y) as.data.frame(t(sapply(a, rbind))) lapply(a, function(x) matrix(unlist(x), nrow = length(x), byrow = TRUE)) but I don't know how to fix it. Regards, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
[R] Remove empty list from list
Dear all, I am still working with "list". If I have an empty list how can I remove from list data. Here is a toy example: x <- list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4)) y <- list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1),c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1),c(-1, -1, -1, -1, -1)) ## Thanks to Gabor Grothendieck for this trick. ## SIMPLIFY? SIMPLIFY >< simplify xy.list <- mapply(cbind, x, y, SIMPLIFY=FALSE) point.class <- t(cbind(c(10,20,15,4,-1),c(21,10,15,34,-1),c(11,13,6,3,1),c(7,5,5,2,1),c(8,9,5,12,-1))) class.diffsame <- points.neighb(as.matrix(point.class), xy.list, 5) pd.class <- points.diff(class.diffsame,xy.list) nc.test <- vector("list",length(pd.class)) for (i in 1:length(pd.class)) { nc.test[[i]] <- pd.class[[i]]$point.diff } nc.test > nc.test [[1]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 161 [2,]49 14 191 [3,]5 10 15 201 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 161 [2,]27 12 171 [[3]] [,1] [,2] [,3] [,4] [,5] [[4]] [,1] [,2] [,3] [,4] [,5] [1,]38 13 18 -1 [2,]5 10 15 20 -1 [[5]] [,1] [,2] [,3] [,4] [,5] > I want to remove these: nc.test[[3]] nc.test[[5]] Because my list data have more 1000 lists are there any simple way to do this? Best, Muhammad Subianto points.neighb <- function(p.class, list.nc, class.col) { ntuples <- nrow(p.class) instvec <- vector("list",length=ntuples) for (i in 1:ntuples) { # Thanks to Petr Pikal for this trick instvec[[i]]$class.diff <- (p.class[i,class.col] - list.nc[[i]][,class.col])!=0 instvec[[i]]$class.same <- (p.class[i,class.col] - list.nc[[i]][,class.col])==0 } instvec } points.diff <- function(p.class, list.nc) { ntuples <- length(list.nc) instvec <- vector("list",ntuples) for (i in 1:ntuples) { instvec[[i]]$point.diff <- list.nc[[i]][p.class[[i]]$class.diff,] instvec[[i]]$point.same <- list.nc[[i]][p.class[[i]]$class.same,] } instvec } __ R-help@stat.math.ethz.ch 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.
Re: [R] Remove empty list from list
On this day 28/08/2006 19:20, Muhammad Subianto wrote: > Dear all, > I am still working with "list". > If I have an empty list how can I remove from list data. > Here is a toy example: > x <- list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, > 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4)) > y <- list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1),c(1, 1, 1, 1, 1),c(1, > 1, -1, 1, -1),c(-1, -1, -1, -1, -1)) > ## Thanks to Gabor Grothendieck for this trick. > ## SIMPLIFY? SIMPLIFY >< simplify > xy.list <- mapply(cbind, x, y, SIMPLIFY=FALSE) > > point.class <- > t(cbind(c(10,20,15,4,-1),c(21,10,15,34,-1),c(11,13,6,3,1),c(7,5,5,2,1),c(8,9,5,12,-1))) > class.diffsame <- points.neighb(as.matrix(point.class), xy.list, 5) > pd.class <- points.diff(class.diffsame,xy.list) > > nc.test <- vector("list",length(pd.class)) > for (i in 1:length(pd.class)) { > nc.test[[i]] <- pd.class[[i]]$point.diff > } > nc.test >> nc.test > [[1]] > [,1] [,2] [,3] [,4] [,5] > [1,]16 11 161 > [2,]49 14 191 > [3,]5 10 15 201 > > [[2]] > [,1] [,2] [,3] [,4] [,5] > [1,]16 11 161 > [2,]27 12 171 > > [[3]] > [,1] [,2] [,3] [,4] [,5] > > [[4]] > [,1] [,2] [,3] [,4] [,5] > [1,]38 13 18 -1 > [2,]5 10 15 20 -1 > > [[5]] > [,1] [,2] [,3] [,4] [,5] > > I want to remove these: > nc.test[[3]] > nc.test[[5]] > Because my list data have more 1000 lists are there any simple way to do this? > > Best, Muhammad Subianto > > > points.neighb <- function(p.class, list.nc, class.col) { >ntuples <- nrow(p.class) >instvec <- vector("list",length=ntuples) >for (i in 1:ntuples) { > # Thanks to Petr Pikal for this trick > instvec[[i]]$class.diff <- (p.class[i,class.col] - > list.nc[[i]][,class.col])!=0 > instvec[[i]]$class.same <- (p.class[i,class.col] - > list.nc[[i]][,class.col])==0 >} >instvec > } > > points.diff <- function(p.class, list.nc) { >ntuples <- length(list.nc) >instvec <- vector("list",ntuples) >for (i in 1:ntuples) { > instvec[[i]]$point.diff <- list.nc[[i]][p.class[[i]]$class.diff,] > instvec[[i]]$point.same <- list.nc[[i]][p.class[[i]]$class.same,] >} >instvec > } > Dear Jim Holtman and Gabor Grothendieck, Thank you both very much for the suggestions! These is exactly what I was looking for. Best wishes, Muhammad Subianto ## delete null/empty entries in a list delete.NULLs <- function(x.list){ x.list[unlist(lapply(x.list, length) != 0)] } > delete.NULLs <- function(x.list){ + x.list[unlist(lapply(x.list, length) != 0)] + } > delete.NULLs <- function(x.list){ + x.list[unlist(lapply(x.list, length) != 0)] + } > > delete.NULLs(nc.test) [[1]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 161 [2,]49 14 191 [3,]5 10 15 201 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 161 [2,]27 12 171 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]38 13 18 -1 [2,]5 10 15 20 -1 > __ R-help@stat.math.ethz.ch 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.
Re: [R] Remove empty list from list - remove only one row and make as matrix
Dear all, After I work around, I found in my list of data with only one row which need to remove or make it as matrix. Here I write again my other toy example: x <- list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4)) y <- list(c(1, -1, -1, 1, 1),c(1, -1, -1, -1, -1),c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1),c(-1, -1, -1, -1, -1)) ## Thanks to Gabor Grothendieck for this trick. ## SIMPLIFY? SIMPLIFY >< simplify xy.list <- mapply(cbind, x, y, SIMPLIFY=FALSE) point.class <- t(cbind(c(10,20,15,4,-1),c(21,10,15,34,-1),c(11,13,6,3,1),c(7,5,5,2,1),c(8,9,5,12,-1))) class.diffsame <- points.neighb(as.matrix(point.class), xy.list, 5) pd.class <- points.diff(class.diffsame,xy.list) nc.test <- vector("list",length(pd.class)) for (i in 1:length(pd.class)) { nc.test[[i]] <- pd.class[[i]]$point.diff } nc.test # delete null/empty entries in a list dff <- delete.NULLs(nc.test) dff; str(dff) > dff [[1]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 161 [2,]49 14 191 [3,]5 10 15 201 [[2]] [1] 1 6 11 16 1 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]38 13 18 -1 [2,]5 10 15 20 -1 > lapply(dff, nrow) > lapply(dff, nrow) [[1]] [1] 3 [[2]] NULL [[3]] [1] 2 > #I can use #dff[unlist(lapply(dff, nrow) == 1)] #2,3, etc I have two questions here: a. I need to remove dff[[2]] b. How to make it as matrix (in list). I mean the result something like [[1]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 161 [2,]49 14 191 [3,]5 10 15 201 [[2]] [,1] [,2] [,3] [,4] [,5] [1]1611 161 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]38 13 18 -1 [2,]5 10 15 20 -1 Best, Muhammad Subianto points.neighb <- function(p.class, list.nc, class.col) { ntuples <- nrow(p.class) instvec <- vector("list",length=ntuples) for (i in 1:ntuples) { # Thanks to Petr Pikal for this trick instvec[[i]]$class.diff <- (p.class[i,class.col] - list.nc[[i]][,class.col])!=0 instvec[[i]]$class.same <- (p.class[i,class.col] - list.nc[[i]][,class.col])==0 } instvec } points.diff <- function(p.class, list.nc) { ntuples <- length(list.nc) instvec <- vector("list",ntuples) for (i in 1:ntuples) { instvec[[i]]$point.diff <- list.nc[[i]][p.class[[i]]$class.diff,] instvec[[i]]$point.same <- list.nc[[i]][p.class[[i]]$class.same,] } instvec } # Thanks to Jim Holtman for this trick delete.NULLs <- function(x.list){ x.list[unlist(lapply(x.list, length) != 0)] } __ R-help@stat.math.ethz.ch 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.
Re: [R] Remove empty list from list - remove only one row and make as matrix
Dear all, Dimitris, thanks for your great help and quick response. Best, Muhammad Subianto > dff[sapply(dff, is.matrix)] [[1]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 161 [2,]49 14 191 [3,]5 10 15 201 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]38 13 18 -1 [2,]5 10 15 20 -1 > lapply(dff, function(x) if(!is.matrix(x)) rbind(x) else x) [[1]] [,1] [,2] [,3] [,4] [,5] [1,]16 11 161 [2,]49 14 191 [3,]5 10 15 201 [[2]] [,1] [,2] [,3] [,4] [,5] x16 11 161 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]38 13 18 -1 [2,]5 10 15 20 -1 > On this day 29/08/2006 13:34, Dimitris Rizopoulos wrote: > try the following: > > # a > dff[sapply(dff, is.matrix)] > > # b > lapply(dff, function(x) if(!is.matrix(x)) rbind(x) else x) > > > I hope it helps. > > Best, > Dimitris > > > Dimitris Rizopoulos > Ph.D. Student > Biostatistical Centre > School of Public Health > Catholic University of Leuven > > Address: Kapucijnenvoer 35, Leuven, Belgium > Tel: +32/(0)16/336899 > Fax: +32/(0)16/337015 > Web: http://med.kuleuven.be/biostat/ > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > - Original Message - > From: "Muhammad Subianto" <[EMAIL PROTECTED]> > To: > Sent: Tuesday, August 29, 2006 1:22 PM > Subject: Re: [R] Remove empty list from list - remove only one row and > make as matrix > > >> Dear all, >> After I work around, I found in my list of data with only one row >> which >> need to remove or make it as matrix. >> Here I write again my other toy example: >> x <- list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, >> 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4)) >> y <- list(c(1, -1, -1, 1, 1),c(1, -1, -1, -1, -1),c(1, 1, 1, 1, >> 1),c(1, >> 1, -1, 1, -1),c(-1, -1, -1, -1, -1)) >> ## Thanks to Gabor Grothendieck for this trick. >> ## SIMPLIFY? SIMPLIFY >< simplify >> xy.list <- mapply(cbind, x, y, SIMPLIFY=FALSE) >> >> point.class <- >> t(cbind(c(10,20,15,4,-1),c(21,10,15,34,-1),c(11,13,6,3,1),c(7,5,5,2,1),c(8,9,5,12,-1))) >> class.diffsame <- points.neighb(as.matrix(point.class), xy.list, 5) >> pd.class <- points.diff(class.diffsame,xy.list) >> >> nc.test <- vector("list",length(pd.class)) >> for (i in 1:length(pd.class)) { >> nc.test[[i]] <- pd.class[[i]]$point.diff >> } >> nc.test >> >> # delete null/empty entries in a list >> dff <- delete.NULLs(nc.test) >> dff; str(dff) >>> dff >> [[1]] >> [,1] [,2] [,3] [,4] [,5] >> [1,]16 11 161 >> [2,]49 14 191 >> [3,]5 10 15 201 >> >> [[2]] >> [1] 1 6 11 16 1 >> >> [[3]] >> [,1] [,2] [,3] [,4] [,5] >> [1,]38 13 18 -1 >> [2,]5 10 15 20 -1 >> >> lapply(dff, nrow) >>> lapply(dff, nrow) >> [[1]] >> [1] 3 >> >> [[2]] >> NULL >> >> [[3]] >> [1] 2 >> >> #I can use >> #dff[unlist(lapply(dff, nrow) == 1)] #2,3, etc >> >> I have two questions here: >> a. I need to remove dff[[2]] >> b. How to make it as matrix (in list). I mean the result something >> like >> >> [[1]] >> [,1] [,2] [,3] [,4] [,5] >> [1,]16 11 161 >> [2,]49 14 191 >> [3,]5 10 15 201 >> >> [[2]] >> [,1] [,2] [,3] [,4] [,5] >> [1]1611 161 >> >> [[3]] >> [,1] [,2] [,3] [,4] [,5] >> [1,]38 13 18 -1 >> [2,]5 10 15 20 -1 >> >> >> Best, Muhammad Subianto >> >> >> points.neighb <- function(p.class, list.nc, class.col) { >>ntuples <- nrow(p.class) >>instvec <- vector("list",length=ntuples) >>for (i in 1:ntuples) { >> # Thanks to Petr Pikal for this trick >> instvec[[i]]$class.diff <- (p.class[i,class.col] - >> list.nc[[i]][,class.col])!=0 >> instvec[[i]]$class.same <- (p.class[i,class.col] - >> list.nc[[i]][,class.col])==0 >>} >>instvec >> } >> >> points.diff <- function(p.class, list.nc) { >>ntuples <- length(list.nc) >>instvec <- vector("list",ntuples) >>for (i in 1:ntuples) { >> instvec[[i]]$point.diff <- >> list.nc[[i]][p.class[[i]]$class.diff,] >> instvec[[i]]$point.same <- >> list.nc[[i]][p.class[[i]]$class.same,] >>} >>instvec >> } >> >> # Thanks to Jim Holtman for this trick >> delete.NULLs <- function(x.list){ >> x.list[unlist(lapply(x.list, length) != 0)] >> } >> __ R-help@stat.math.ethz.ch 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.
[R] Barplot
Dear all, I have a dataset. I want to make barplot from this data. Zero1 <- " V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1 0 0 0 1 0 0 0 Positive 2 0 0 1 0 1 0 1 1 Negative 3 0 0 1 0 0 0 1 1 Positive 4 0 1 0 1 1 1 0 1 Negative 5 0 0 1 0 1 1 0 0 Positive 6 0 1 0 0 1 1 1 1 Negative 7 1 0 1 1 1 1 1 1 Negative 8 0 0 0 0 1 0 0 1 Negative 9 0 1 1 1 1 0 0 1 Negative 10 0 0 0 1 1 0 1 0 Positive 11 0 0 0 0 1 0 0 1 Negative 12 0 0 1 1 1 1 1 0 Positive 13 0 1 1 0 1 1 1 1 Negative" z1 <- read.table(textConnection(Zero1), header=TRUE) z1 str(z1) A simple way I can use mosaic plot mosaicplot(table(z1)) library(vcd) mosaic(table(z1)) I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. I need a barplot for all variables and the result maybe like | | | | | | | | | || | | |pos|neg| |pos|neg||pos|neg| | | | | | || | | - -- v1v2v3 v7 v8 Thanks you for any helps. Regards, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
Re: [R] Barplot - thanks
Dear all, Many Thanks to Jacques VESLOT and Jim Lemon for their helps. Best, Muhammad Subianto #Jacques VESLOT barplot(t(sapply(split(z1[,1:8], z1$V9),colSums)), beside=T) #Jim Lemon barplot(sapply(z1[1:8],by,z1[9],sum),beside=TRUE) On this day 30/08/2006 11:43, Muhammad Subianto wrote: > Dear all, > I have a dataset. I want to make barplot from this data. > Zero1 <- " >V1 V2 V3 V4 V5 V6 V7 V8 V9 > 1 1 0 0 0 1 0 0 0 Positive > 2 0 0 1 0 1 0 1 1 Negative > 3 0 0 1 0 0 0 1 1 Positive > 4 0 1 0 1 1 1 0 1 Negative > 5 0 0 1 0 1 1 0 0 Positive > 6 0 1 0 0 1 1 1 1 Negative > 7 1 0 1 1 1 1 1 1 Negative > 8 0 0 0 0 1 0 0 1 Negative > 9 0 1 1 1 1 0 0 1 Negative > 10 0 0 0 1 1 0 1 0 Positive > 11 0 0 0 0 1 0 0 1 Negative > 12 0 0 1 1 1 1 1 0 Positive > 13 0 1 1 0 1 1 1 1 Negative" > > z1 <- read.table(textConnection(Zero1), header=TRUE) > z1 > str(z1) > > A simple way I can use mosaic plot > mosaicplot(table(z1)) > library(vcd) > mosaic(table(z1)) > > I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. > I need a barplot for all variables and the result maybe like > > | | | | > | | | | | || | | > |pos|neg| |pos|neg||pos|neg| > | | | | | || | | > ----- -- > v1v2v3 v7 v8 > > Thanks you for any helps. > Regards, Muhammad Subianto > __ R-help@stat.math.ethz.ch 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.
Re: [R] Barplot
Dear all, To Gabor Grothendieck, (again) thanks you very much for your help. Now, I can play around with lattice package. Best, Muhammad Subianto #Gabor #reduce the data to a frequency matrix and #then plot it using classic and then lattice graphics: zm <- as.matrix(rowsum(z1[-9], z1[,9])) barplot(zm, beside = TRUE, col = grey.colors(2)) legend("topleft", legend = levels(z1[,9]), fill = grey.colors(2)) library(lattice) barchart(Freq ~ Var2, as.data.frame.table(zm), groups = Var1, origin = 0, auto.key = TRUE) On this day 30/08/2006 16:18, Gabor Grothendieck wrote: > Try this. First we reduce the data to a frequency matrix and > then plot it using classic and then lattice graphics: > > zm <- as.matrix(rowsum(z1[-9], z1[,9])) > > barplot(zm, beside = TRUE, col = grey.colors(2)) > legend("topleft", legend = levels(z1[,9]), fill = grey.colors(2)) > > library(lattice) > barchart(Freq ~ Var2, as.data.frame.table(zm), > groups = Var1, origin = 0, auto.key = TRUE) > > On 8/30/06, Muhammad Subianto <[EMAIL PROTECTED]> wrote: >> Dear all, >> I have a dataset. I want to make barplot from this data. >> Zero1 <- " >> V1 V2 V3 V4 V5 V6 V7 V8 V9 >> 1 1 0 0 0 1 0 0 0 Positive >> 2 0 0 1 0 1 0 1 1 Negative >> 3 0 0 1 0 0 0 1 1 Positive >> 4 0 1 0 1 1 1 0 1 Negative >> 5 0 0 1 0 1 1 0 0 Positive >> 6 0 1 0 0 1 1 1 1 Negative >> 7 1 0 1 1 1 1 1 1 Negative >> 8 0 0 0 0 1 0 0 1 Negative >> 9 0 1 1 1 1 0 0 1 Negative >> 10 0 0 0 1 1 0 1 0 Positive >> 11 0 0 0 0 1 0 0 1 Negative >> 12 0 0 1 1 1 1 1 0 Positive >> 13 0 1 1 0 1 1 1 1 Negative" >> >> z1 <- read.table(textConnection(Zero1), header=TRUE) >> z1 >> str(z1) >> >> A simple way I can use mosaic plot >> mosaicplot(table(z1)) >> library(vcd) >> mosaic(table(z1)) >> >> I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. >> I need a barplot for all variables and the result maybe like >> >> | | | | >> | | | | | || | | >> |pos|neg| |pos|neg||pos|neg| >> | | | | | || | | >> - -- >>v1v2v3 v7 v8 >> >> Thanks you for any helps. >> Regards, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
Re: [R] Merge list to list - as list
Dear all, #Last week, I asked about merge x and y as list. #Now I have a dataset with list of list like: x <- list(list(matrix(1:20, 5, 4),matrix(1:20, 5, 4)), list(matrix(1:20, 5, 4),matrix(1:20, 5, 4))) y <- list(list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1)), list(c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1))) x y #I need merge x and y, I have tried with list.uni <- vector("list", length(x)) for (i in 1:length(x)) { for (j in 1:length(x[[1]])) { list.uni[[i]][[j]] <- mapply(cbind, x[[i]][[j]], y[[i]][[j]], SIMPLIFY=FALSE) } } list.uni I have learn about ?lapply, ?sapply and ?mapply but I still didn't understand how to use it. I need the result something like [[1]] [[1]][[1]] [,1] [,2] [,3] [,4] [5] [1,]16 11 16 1 [2,]27 12 17 -1 [3,]38 13 18 -1 [4,]49 14 19 1 [5,]5 10 15 20 1 [[1]][[2]] [,1] [,2] [,3] [,4] [5] [1,]16 11 16 1 [2,]27 12 17 1 [3,]38 13 18 -1 [4,]49 14 19 -1 [5,]5 10 15 20 -1 [[2]] [[2]][[1]] [,1] [,2] [,3] [,4] [5] [1,]16 11 16 1 [2,]27 12 17 1 [3,]38 13 18 1 [4,]49 14 19 1 [5,]5 10 15 20 1 [[2]][[2]] [,1] [,2] [,3] [,4] [5] [1,]16 11 16 1 [2,]27 12 17 1 [3,]38 13 18 -1 [4,]49 14 19 1 [5,]5 10 15 20 -1 Thanks you for any help. Best wishes, Muhammad Subianto #Gabor Grothendieck ggrothendieck at gmail.com #Mon Aug 28 13:53:52 CEST 2006 Here are two ways: 1. use indexes: lapply(seq(along = x), function(i) cbind(x[[i]], y[[i]])) 2. use mapply: mapply(cbind, x, y, SIMPLIFY = FALSE) On 8/28/06, Muhammad Subianto wrote: > Dear all, > > I have dataset > x <- list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4)) > y <- list(matrix(110:114, 5, 1),matrix(110:114, 5, 1),matrix(110:114, 5, 1)) > > I need merge x and y as list (y put in last column). > The result is something like > > [[1]] > [,1] [,2] [,3] [,4] [,5] > [1,]16 11 16 110 > [2,]27 12 17 111 > [3,]38 13 18 112 > [4,]49 14 19 113 > [5,]5 10 15 20 114 > > [[2]] > [,1] [,2] [,3] [,4] [,5] > [1,]16 11 16 110 > [2,]27 12 17 111 > [3,]38 13 18 112 > [4,]49 14 19 113 > [5,]5 10 15 20 114 > > [[3]] > [,1] [,2] [,3] [,4] [,5] > [1,]16 11 16 110 > [2,]27 12 17 111 > [3,]38 13 18 112 > [4,]49 14 19 113 > [5,]5 10 15 20 114 > > I have tried > a <- list(x,y) > as.data.frame(t(sapply(a, rbind))) > lapply(a, function(x) matrix(unlist(x), nrow = length(x), byrow = TRUE)) > but I don't know how to fix it. > > Regards, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
Re: [R] Merge list to list - as list
Dear all, Many thanks to Gabor Grothendieck and Jim Holtman, both of you always reply (to answer) my problems. Regards, Muhammad Subianto ##Gabor Grothendieck If z is the result then z[[i]] is formed from x[[i]] and y[[i]] using the previous solution, viz. z <- list() z[[1]] <- mapply(cbind, x[[1]], y[[1]], SIMPLIFY = FALSE) z[[2]] <- mapply(cbind, x[[2]], y[[2]], SIMPLIFY = FALSE) or with a for loop (which is similar to the code you posted below except the extraneous j loop is removed since its already incorporated in the mapply): z <- list() for(i in seq(along = x)) z[[i]] <- mapply(cbind, x[[1]], y[[1]], SIMPLIFY = FALSE) or reducing the loop to a lapply: lapply(seq(along = x), function(i) mapply(cbind, x[[i]], y[[i]], SIMPLIFY = FALSE)) ## Gabor Grothendieck cbind2 <- function(x, y) { if (is.list(x)) mapply(cbind2, x, y, SIMPLIFY = FALSE) else cbind(x,y) } x <- list(list(matrix(1:20, 5, 4),matrix(1:20, 5, 4)), list(matrix(1:20, 5, 4),matrix(1:20, 5, 4))) y <- list(list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1)), list(c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1))) cbind2(x,y) cbind2(x[[1]], y[[1]]) cbind2(x[[1]][[1]], y[[1]][[1]]) ## Jim Holtman list.uni <- vector("list", length(x)) for (i in 1:length(x)) { for (j in 1:length(x[[1]])) { list.uni[[i]][[j]] <- cbind(x[[i]][[j]],y[[i]][[j]]) } } list.uni On 9/3/06, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > Dear all, > #Last week, I asked about merge x and y as list. > #Now I have a dataset with list of list like: > x <- list(list(matrix(1:20, 5, 4),matrix(1:20, 5, 4)), > list(matrix(1:20, 5, 4),matrix(1:20, 5, 4))) > y <- list(list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1)), > list(c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1))) > x > y > > #I need merge x and y, I have tried with > list.uni <- vector("list", length(x)) > for (i in 1:length(x)) { > for (j in 1:length(x[[1]])) { > list.uni[[i]][[j]] <- mapply(cbind, >x[[i]][[j]], >y[[i]][[j]], >SIMPLIFY=FALSE) > } > } > list.uni > > I have learn about ?lapply, ?sapply and ?mapply but I still didn't > understand how to use it. > I need the result something like > > > [[1]] > [[1]][[1]] > [,1] [,2] [,3] [,4] [5] > [1,]16 11 16 1 > [2,]27 12 17 -1 > [3,]38 13 18 -1 > [4,]49 14 19 1 > [5,]5 10 15 20 1 > > [[1]][[2]] > [,1] [,2] [,3] [,4] [5] > [1,]16 11 16 1 > [2,]27 12 17 1 > [3,]38 13 18 -1 > [4,]49 14 19 -1 > [5,]5 10 15 20 -1 > > > [[2]] > [[2]][[1]] > [,1] [,2] [,3] [,4] [5] > [1,]16 11 16 1 > [2,]27 12 17 1 > [3,]38 13 18 1 > [4,]49 14 19 1 > [5,]5 10 15 20 1 > > [[2]][[2]] > [,1] [,2] [,3] [,4] [5] > [1,]16 11 16 1 > [2,]27 12 17 1 > [3,]38 13 18 -1 > [4,]49 14 19 1 > [5,]5 10 15 20 -1 > > Thanks you for any help. > Best wishes, Muhammad Subianto > > > > > #Gabor Grothendieck ggrothendieck at gmail.com > #Mon Aug 28 13:53:52 CEST 2006 > > Here are two ways: > > 1. use indexes: > > lapply(seq(along = x), function(i) cbind(x[[i]], y[[i]])) > > 2. use mapply: > > mapply(cbind, x, y, SIMPLIFY = FALSE) > > > On 8/28/06, Muhammad Subianto wrote: > > Dear all, > > > > I have dataset > > x <- list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4)) > > y <- list(matrix(110:114, 5, 1),matrix(110:114, 5, 1),matrix(110:114, 5, 1)) > > > > I need merge x and y as list (y put in last column). > > The result is something like > > > > [[1]] > > [,1] [,2] [,3] [,4] [,5] > > [1,]16 11 16 110 > > [2,]27 12 17 111 > > [3,]38 13 18 112 > > [4,]49 14 19 113 > > [5,]5 10 15 20 114 > > > > [[2]] > > [,1] [,2] [,3] [,4] [,5] > > [1,]16 11 16 110 > > [2,]27 12 17 111 > > [3,]38 13 18 112 > > [4,]49 14 19 113 > > [5,]5 10 15 20 114 > > > > [[3]] > > [,1] [,2] [,3] [,4] [,5] > > [1,]16 11 16 110 > > [2,]27 12 17 111 > > [3,]38 13 18 112 > > [4,]49 14 19 113 > > [5,]5 10 15 20 114 > > > > I have tried > > a <- list(x,y) > > as.data.frame(t(sapply(a, rbind))) > > lapply(a, function(x) matrix(unlist(x), nrow = length(x), byrow = TRUE)) > > but I don't know how to fix it. > > > > Regards, Muhammad Subianto > __ R-help@stat.math.ethz.ch 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.
[R] load file RData which store in zip file
Dear R users, My situation: (1) I have limited workspace for my work harddisk (about 10 GiB). (2) I have a lot of data files in R workspace (*.RData) which most of them > 200 MiB. For some reason I zip some of them, for instance "filename.RData (250 MiB)" to "filename.zip (3MiB)". In this work I have a lot of more space of my harddisk. Normally, If I want to use "filename.RData" for my experiment, I can do it with load("filename.RData"). Then I tried to open/load > load("filename.zip") Error: bad restore file magic number (file may be corrupted) -- no data loaded > My question: How can I open/load "filename.zip"? Is there any function to open R workspace which it store in zip file? I hope some one can give me advices. Best, Muhammad Subianto > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.1 year 2005 month12 day 20 svn rev 36812 language R > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] load file RData which store in zip file
I apologize for my lack of knowledge. Thank you very much for the suggestions. These are exactly what I was looking for. > ?zip.file.extract Help for 'zip.file.extract' is shown in the browser Maybe I must re-run and re-save again to compress my R workspace. > ?save.image Help for 'save.image' is shown in the browser Regards, Muhammad Subianto On 3/29/06, Philipp Pagel <[EMAIL PROTECTED]> wrote: > On Wed, Mar 29, 2006 at 11:44:03AM +0200, Muhammad Subianto wrote: > > How can I open/load "filename.zip"? Is there any function to open R > > workspace which it store in zip file? > > I think you have two options: > > 1) use zip.file.extract() to unzip the file before loading > > 2) save your data with save.image(file="foo.RData", compress = True) > > cu > Philipp > > -- > Dr. Philipp PagelTel. +49-8161-71 2131 > Dept. of Genome Oriented Bioinformatics Fax. +49-8161-71 2186 > Technical University of Munich > Science Center Weihenstephan > 85350 Freising, Germany > > and > > Institute for Bioinformatics / MIPS Tel. +49-89-3187 3675 > GSF - National Research Center Fax. +49-89-3187 3585 > for Environment and Health > Ingolstädter Landstrasse 1 > 85764 Neuherberg, Germany > http://mips.gsf.de/staff/pagel > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] convert a data frame to matrix - changed column name
I have a question, which very easy to solve, but I can't find a solution. I want to convert a data frame to matrix. Here my toy example: > L3 <- c(1:3) > L10 <- c(1:6) > d <- data.frame(cbind(x=c(10,20), y=L10), fac=sample(L3, + 6, repl=TRUE)) > d x y fac 1 10 1 1 2 20 2 1 3 10 3 1 4 20 4 3 5 10 5 2 6 20 6 2 > is.data.frame(d) [1] TRUE > sapply(d, function(x) unlist(x, use.names=FALSE)) x y fac [1,] 10 1 1 [2,] 20 2 1 [3,] 10 3 1 [4,] 20 4 3 [5,] 10 5 2 [6,] 20 6 2 > is.matrix(sapply(d, function(x) unlist(x, use.names=FALSE))) [1] TRUE > Yes, I get a matrix TRUE. But I need to change a column name like [,1] [,2] [,3]. I need the result like [,1] [,2] [,3] [1,] 1011 [2,] 2021 [3,] 1031 [4,] 2043 [5,] 1052 [6,] 2062 How can I do that? Thanks in advance, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] convert a data frame to matrix - changed column name
On this day 06/04/2006 16:22, Robin Hankin wrote: > Hi > > set the column names to NULL: > > > > a <- data.frame(x=1:4,y=4:1) > > aa <- as.matrix(a) > > colnames(aa) <- NULL > > aa On this day 06/04/2006 16:28, Dimitris Rizopoulos wrote: > try the following: > > out <- data.matrix(d) > dimnames(out) <- NULL > out Thank you very much for your help. Best, Muhammad Subianto On 4/6/06, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > I have a question, which very easy to solve, but I can't find a solution. > I want to convert a data frame to matrix. Here my toy example: > > > L3 <- c(1:3) > > L10 <- c(1:6) > > d <- data.frame(cbind(x=c(10,20), y=L10), fac=sample(L3, + 6, repl=TRUE)) > > d >x y fac > 1 10 1 1 > 2 20 2 1 > 3 10 3 1 > 4 20 4 3 > 5 10 5 2 > 6 20 6 2 > > is.data.frame(d) > [1] TRUE > > sapply(d, function(x) unlist(x, use.names=FALSE)) > x y fac > [1,] 10 1 1 > [2,] 20 2 1 > [3,] 10 3 1 > [4,] 20 4 3 > [5,] 10 5 2 > [6,] 20 6 2 > > is.matrix(sapply(d, function(x) unlist(x, use.names=FALSE))) > [1] TRUE > > > > Yes, I get a matrix TRUE. But I need to change a column name like [,1] > [,2] [,3]. I need the result like > > [,1] [,2] [,3] > [1,] 1011 > [2,] 2021 > [3,] 1031 > [4,] 2043 > [5,] 1052 > [6,] 2062 > > How can I do that? > Thanks in advance, Muhammad Subianto > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] About list to list
Dear all, I have a result my experiment like this below (here my toy example): foo1 <- list() foo1[[1]] <- c(10, 20, 30) foo1[[2]] <- c(11, 21, 31) foo2 <- list() foo2[[1]] <- c(100, 200, 300) foo2[[2]] <- c(110, 210, 310) foo3 <- list() foo3[[1]] <- c(1000, 2000, 3000) foo3[[2]] <- c(1100, 2100, 3100) list(foo1,foo2,foo3) The result: > list(foo1,foo2,foo3) [[1]] [[1]][[1]] [1] 10 20 30 [[1]][[2]] [1] 11 21 31 [[2]] [[2]][[1]] [1] 100 200 300 [[2]][[2]] [1] 110 210 310 [[3]] [[3]][[1]] [1] 1000 2000 3000 [[3]][[2]] [1] 1100 2100 3100 > I want to convert like this below (as list). [[1]] [1] 10 20 30 [2] 11 21 31 [[2]] [1] 100 200 300 [2] 110 210 310 [[3]] [1] 1000 2000 3000 [2] 1100 2100 3100 I saw on the R-help archives page similar like this but I can't find a solution. http://tolstoy.newcastle.edu.au/R/help/05/05/4678.html Thanks very much for any suggestions. Sincerely, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] About list to list - thanks
Thank you very much for your useful suggestions. These are exactly what I was looking for. foo <- list(foo1, foo2, foo3) lapply(foo, function(x) matrix(unlist(x), nrow = length(x), byrow = TRUE)) or lapply(foo, function(x) do.call('rbind', x)) Best, Muhammad Subianto On 4/11/06, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > Dear all, > I have a result my experiment like this below (here my toy example): > > foo1 <- list() > foo1[[1]] <- c(10, 20, 30) > foo1[[2]] <- c(11, 21, 31) > > foo2 <- list() > foo2[[1]] <- c(100, 200, 300) > foo2[[2]] <- c(110, 210, 310) > > foo3 <- list() > foo3[[1]] <- c(1000, 2000, 3000) > foo3[[2]] <- c(1100, 2100, 3100) > > list(foo1,foo2,foo3) > > The result: > > list(foo1,foo2,foo3) > [[1]] > [[1]][[1]] > [1] 10 20 30 > > [[1]][[2]] > [1] 11 21 31 > > [[2]] > [[2]][[1]] > [1] 100 200 300 > > [[2]][[2]] > [1] 110 210 310 > > [[3]] > [[3]][[1]] > [1] 1000 2000 3000 > > [[3]][[2]] > [1] 1100 2100 3100 > > > > I want to convert like this below (as list). > > [[1]] > [1] 10 20 30 > [2] 11 21 31 > > [[2]] > [1] 100 200 300 > [2] 110 210 310 > > [[3]] > [1] 1000 2000 3000 > [2] 1100 2100 3100 > > I saw on the R-help archives page similar like this but I can't find a > solution. > http://tolstoy.newcastle.edu.au/R/help/05/05/4678.html > Thanks very much for any suggestions. > > Sincerely, Muhammad Subianto > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] About list to list - thanks
Thank you very much for your useful suggestions. These are exactly what I was looking for. foo <- list(foo1, foo2, foo3) lapply(foo, function(x) matrix(unlist(x), nrow = length(x), byrow = TRUE)) or lapply(foo, function(x) do.call('rbind', x)) Best, Muhammad Subianto On 4/11/06, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > Dear all, > I have a result my experiment like this below (here my toy example): > > foo1 <- list() > foo1[[1]] <- c(10, 20, 30) > foo1[[2]] <- c(11, 21, 31) > > foo2 <- list() > foo2[[1]] <- c(100, 200, 300) > foo2[[2]] <- c(110, 210, 310) > > foo3 <- list() > foo3[[1]] <- c(1000, 2000, 3000) > foo3[[2]] <- c(1100, 2100, 3100) > > list(foo1,foo2,foo3) > > The result: > > list(foo1,foo2,foo3) > [[1]] > [[1]][[1]] > [1] 10 20 30 > > [[1]][[2]] > [1] 11 21 31 > > [[2]] > [[2]][[1]] > [1] 100 200 300 > > [[2]][[2]] > [1] 110 210 310 > > [[3]] > [[3]][[1]] > [1] 1000 2000 3000 > > [[3]][[2]] > [1] 1100 2100 3100 > > > > I want to convert like this below (as list). > > [[1]] > [1] 10 20 30 > [2] 11 21 31 > > [[2]] > [1] 100 200 300 > [2] 110 210 310 > > [[3]] > [1] 1000 2000 3000 > [2] 1100 2100 3100 > > I saw on the R-help archives page similar like this but I can't find a > solution. > http://tolstoy.newcastle.edu.au/R/help/05/05/4678.html > Thanks very much for any suggestions. > > Sincerely, Muhammad Subianto > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to convert time to days
Dear all, I have ran a simulation in R. This simulation was running about at least two days. Here is below the result some part of my code about time result. I don't understand about Start time: Mon Oct 24, 2005 at 04:23:01 PM Finish time: Wed Oct 26, 2005 at 03:26:19 PM Run time: 1.960625 secs. This is about two seconds or one day and nine hours? Then, how could I convert to 1 day, 23 hours, ? minutes, ? seconds. Thanks you very much for any suggestions. Best wishes, Muhammad Subianto > > # Begin of program and timestamp: > cat(format(begin.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") Mon Oct 24 04:23:01 PM 2005 > cat("Start time:", secs <- format(begin.time, "%X"), "\n") Start time: 04:23:01 PM > cat("Sys.time:", begin.time <- Sys.time(), '\n') Sys.time: 1130163781 > > --- CODE SIMULATION --- > > # End of program and timestamp: > cat("Sys.time:",end.time <- Sys.time(), '\n') Sys.time: 1130333179 > cat("Run Time:",end.time-begin.time, 'secs.\n\n') Run Time: 1.960625 secs. > cat("Finish time:", secs <- format(end.time, "%X"), "\n") Finish time: 03:26:19 PM > cat(format(end.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") Wed Oct 26 03:26:19 PM 2005 > > cat("\n", + " Start time:", secs <- format(begin.time, "%a %b %d, %Y at %X"), "\n", + "Finish time:", secs <- format(end.time, "%a %b %d, %Y at %X"), "\n", + " Run time:", end.time-begin.time, 'secs.\n\n') Start time: Mon Oct 24, 2005 at 04:23:01 PM Finish time: Wed Oct 26, 2005 at 03:26:19 PM Run time: 1.960625 secs. > ### __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to convert time to days
Thanks to everyone for your help. Yuup, this is my stupid word "secs" which I put there. Usually I get to run simulation on my machine only a few seconds. Now, I recode my timestamp, but still I don't know how to make x days, x hours, x minutes, x seconds. Best wishes, Muhammad Subianto On this day 26/10/2005 10:00 PM, Don MacQueen wrote: > The word "secs" appears in "Run time: 1.960625 secs" because you put > it there in your cat() statement. It has nothing to do with the > number itself. > > Simply try typing > > end.time - begin.time > > at the prompt, and see what you get. > > Then see >?difftime > for more information. Example > difftime(end.time,begin.time,units='hours') > > To get the interval formatted as "1 day, 23 hours, x minutes, x > seconds" you will have to do more work. > > -Don > > At 4:18 PM +0200 10/26/05, Muhammad Subianto wrote: > >>Dear all, >>I have ran a simulation in R. >>This simulation was running about at least two days. >>Here is below the result some part of my code about time result. >>I don't understand about >> >>Start time: Mon Oct 24, 2005 at 04:23:01 PM >> Finish time: Wed Oct 26, 2005 at 03:26:19 PM >>Run time: 1.960625 secs. >> >>This is about two seconds or one day and nine hours? >>Then, how could I convert to 1 day, 23 hours, ? minutes, ? seconds. >>Thanks you very much for any suggestions. >> >>Best wishes, Muhammad Subianto >> >> > >> >> > # Begin of program and timestamp: >> > cat(format(begin.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") >>Mon Oct 24 04:23:01 PM 2005 >> > cat("Start time:", secs <- format(begin.time, "%X"), "\n") >>Start time: 04:23:01 PM >> > cat("Sys.time:", begin.time <- Sys.time(), '\n') >>Sys.time: 1130163781 >> > >> > >>--- CODE SIMULATION --- >> > >> > # End of program and timestamp: >> > cat("Sys.time:",end.time <- Sys.time(), '\n') >>Sys.time: 1130333179 >> > cat("Run Time:",end.time-begin.time, 'secs.\n\n') >>Run Time: 1.960625 secs. >> >> > cat("Finish time:", secs <- format(end.time, "%X"), "\n") >>Finish time: 03:26:19 PM >> > cat(format(end.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") >>Wed Oct 26 03:26:19 PM 2005 >> > >> > cat("\n", >>+ " Start time:", secs <- format(begin.time, "%a %b %d, %Y at >>%X"), "\n", >>+ "Finish time:", secs <- format(end.time, "%a %b %d, %Y at >>%X"), "\n", >>+ " Run time:", end.time-begin.time, 'secs.\n\n') >> >> Start time: Mon Oct 24, 2005 at 04:23:01 PM >> Finish time: Wed Oct 26, 2005 at 03:26:19 PM >>Run time: 1.960625 secs. >> >> > >>### >> >>__ >>R-help@stat.math.ethz.ch mailing list >>https://stat.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] how to make automatically each level from data.frame to vector
Dear R-helpers, Suppose I have dataset like this below: data(HairEyeColor) dfHEC <- as.data.frame(as.table(HairEyeColor)) my.dfHEC <- data.frame(Hair=rep(dfHEC$Hair,dfHEC$Freq), Eye=rep(dfHEC$Eye,dfHEC$Freq), Sex=rep(dfHEC$Sex,dfHEC$Freq)) my.dfHEC my.dfHEC$Hair my.dfHEC$Eye my.dfHEC$Sex and I know all levels for Hair, Eye and Sex. In my case, I want to "expand.grid" all attributes but in Hair I only include "Black" hair: Hair.e <- c("Black") Eye.e <- c("Brown","Blue","Hazel","Green") Sex.e <- c("Male","Female") #I can do like, dfHEC.Black <- expand.grid(Hair.e,Eye.e,Sex.e) dfHEC.Black My question is how to make automatically each level from data.frame to vector. I don't want to make definition for each level again (Hair.e, Eye.e, Sex.e). In the others word, how can I make "expand.grid" (each level) from data.frame automatically if Hair is only ("Black"). The result I need like, Var1 Var2 Var3 1 Black Brown Male 2 Black Blue Male 3 Black Hazel Male 4 Black Green Male 5 Black Brown Female 6 Black Blue Female 7 Black Hazel Female 8 Black Green Female Thanks in advance. Best, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How can I put the object name in list
Dear R-helpers, How can I put the object name in list. > Hair <- c("Black","Brown","Red","Blond") > Eye <- c("Brown","Blue","Hazel","Green") > Sex <- c("Male","Female") > > HEC.list <- list(Hair,Eye,Sex) > HEC.list [[1]] [1] "Black" "Brown" "Red" "Blond" [[2]] [1] "Brown" "Blue" "Hazel" "Green" [[3]] [1] "Male" "Female" > I expect the result like this, $Hair [1] "Black" "Brown" "Red" "Blond" $Eye [1] "Brown" "Blue" "Hazel" "Green" $Sex [1] "Male" "Female" Best, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How can I put the object name in list
Yes, thanks you very much. Regards, Muhammad Subianto > HEC.list <- list(Hair=Hair,Eye=Eye,Sex=Sex) > ?list On this day 15/11/2005 12:54 PM, Muhammad Subianto wrote: > Dear R-helpers, > How can I put the object name in list. > > > Hair <- c("Black","Brown","Red","Blond") > > Eye <- c("Brown","Blue","Hazel","Green") > > Sex <- c("Male","Female") > > > > HEC.list <- list(Hair,Eye,Sex) > > HEC.list > [[1]] > [1] "Black" "Brown" "Red" "Blond" > > [[2]] > [1] "Brown" "Blue" "Hazel" "Green" > > [[3]] > [1] "Male" "Female" > > > > I expect the result like this, > > $Hair > [1] "Black" "Brown" "Red" "Blond" > > $Eye > [1] "Brown" "Blue" "Hazel" "Green" > > $Sex > [1] "Male" "Female" > > Best, Muhammad Subianto > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] update R packages in local repos
I try to update R packages via my local repository. I put all R packages in g:/myFolder/myRepository, I do like > library(tools) > write_PACKAGES("g:/myFolder/myRepository") > options(repos=c(LocalR="file://g:/myFolder/myRepository")) > getOption("repos") LocalR "file://g:/myFolder/myRepository" > update.packages(ask = "graphics") Error in gzfile(file, "r") : unable to open connection In addition: Warning message: cannot open compressed file ':/myFolder/myRepository/bin/windows/contrib/2.2/PACKAGES' > > ?update.packages It produces these file in g:/myFolder/myRepository PACKAGES PACKAGES.gz Could I make this folder (bin/windows/contrib/2.2/)? Why? Regards, Muhammad Subianto > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.0 year 2005 month10 day 06 svn rev 35749 language R > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] update R packages in local repos
Thanks you. Now, I can install and update some packages from local repos. I put all R packages (zip files, using W2K) in h:/myFolder/myRepository, library(tools) write_PACKAGES("h:/myFolder/myRepository") options(repos=c(LocalR="file:///h:/myFolder/myRepository")) getOption("repos") install.packages(lib=.libPaths()[3], repos=NULL, contriburl="file:///h:/myFolder/myRepository") instead of install.packages(choose.files('',filters=Filters[c('zip','All'),]), .libPaths()[3], repos = NULL) where .libPaths()[3] my local library (added in Renviron.site) and update with update.packages(ask="graphics", repos=NULL, contriburl="file:///h:/myFolder/myRepository") Best, Muhammad Subianto Cited: - R News 5/1 - C:\Program Files\R\R-2.2.0\library\utils\html\update.packages.html On this day 17/11/2005 08:27 AM, Prof Brian Ripley wrote: > On Wed, 16 Nov 2005, P Ehlers wrote: > > >>This should work: >> >>update.packages(ask = "graphics", repos = NULL, >>contriburl = "file:///g:/myFolder/myRepository")) > > > Only if the so-called repository contains (only) binary builds under R > 2.2.x of packages for Windows. > > It would be better to set up the 'repository' correctly as a repository. > See my article in R-news 5/1 and the R-admin manual for the format of a > repository. > > >>-peter >> >>Muhammad Subianto wrote: >> >>>I try to update R packages via my local repository. >>>I put all R packages in g:/myFolder/myRepository, I do like > > > Are these source packages or binary packages or what? > > >>>>library(tools) >>>>write_PACKAGES("g:/myFolder/myRepository") >>>>options(repos=c(LocalR="file://g:/myFolder/myRepository")) >>>>getOption("repos") >>> >>> LocalR >>>"file://g:/myFolder/myRepository" > > > Your syntax is incorrect here: Peter has silently corrected it. > file:// syntax has an element for 'machine' followed by a third slash > (although 'machine' is not supported in R, so it should be empty). > > >>>>update.packages(ask = "graphics") >>> >>>Error in gzfile(file, "r") : unable to open connection >>>In addition: Warning message: >>>cannot open compressed file >>>':/myFolder/myRepository/bin/windows/contrib/2.2/PACKAGES' >>> >>> >>>>?update.packages >>> >>> >>>It produces these file in g:/myFolder/myRepository >>>PACKAGES >>>PACKAGES.gz >>> >>>Could I make this folder (bin/windows/contrib/2.2/)? Why? > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Help to find only one class and differennt class
Dear R users, I have a problem, which I can not find a solution. Probably someone could help me? I have a result from my classification, like this > credit.toy [[1]] age married ownhouse income gender class 1 20-30 no nolow male good 2 40-50 no yes medium female good [[2]] age married ownhouse income gender class 1 20-30 yes yes high male poor 2 20-30 no yes high male good 3 20-30 yes nolow female poor 4 60-70 yes yeslow female poor 5 60-70 no yes high male poor [[3]] age married ownhouse income gender class 1 30-40 yes no high male good 2 20-30 no yes medium female good [[4]] age married ownhouse income gender class 1 50-60 yes yeslow female poor 2 40-50 yes no medium male poor 3 20-30 no no high female poor [[5]] age married ownhouse income gender class 1 40-50 no yeslow female good 2 60-70 no yes medium male poor 3 30-40 yes no high female poor [[6]] age married ownhouse income gender class 1 30-40 no no medium female good 2 50-60 yes yes high female good 3 30-40 yes no high female good > credit.toy[[5]]$class [1] good poor poor Levels: good poor > How can I count there are only one class and differennt class. I need the result something like good class : 1,3,6 poor class : 4 good and poor class : 2,5 Thanks in advance. Sincerely, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Help to find only one class and differennt class
Thanks to Jim Holtman. This is very usefull to improve my script. Best, Muhammad Subianto On this day 20/12/2005 17:19, jim holtman wrote: >try this: > >set.seed(1) ># generate some test data >x.1 <- data.frame(seg=sample(1:6,20,T), class=sample(c('good', >'poor'),20,T)) >x.1 >(x.sp <- split(x.1, x.1$seg)) ># test each segment for occurance of class. >lapply(x.sp, function(.seg){ >if (all(.seg$class == 'good')) return('good') >if (all(.seg$class == 'poor')) return('poor') >return("good & poor") >}) > > > >On 12/20/05, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > > >>Dear R users, >>I have a problem, which I can not find a solution. >>Probably someone could help me? >>I have a result from my classification, like this >> >> >> >>>credit.toy >>> >>> >>[[1]] >>age married ownhouse income gender class >>1 20-30 no nolow male good >>2 40-50 no yes medium female good >> >>[[2]] >>age married ownhouse income gender class >>1 20-30 yes yes high male poor >>2 20-30 no yes high male good >>3 20-30 yes nolow female poor >>4 60-70 yes yeslow female poor >>5 60-70 no yes high male poor >> >>[[3]] >>age married ownhouse income gender class >>1 30-40 yes no high male good >>2 20-30 no yes medium female good >> >>[[4]] >>age married ownhouse income gender class >>1 50-60 yes yeslow female poor >>2 40-50 yes no medium male poor >>3 20-30 no no high female poor >> >>[[5]] >>age married ownhouse income gender class >>1 40-50 no yeslow female good >>2 60-70 no yes medium male poor >>3 30-40 yes no high female poor >> >>[[6]] >>age married ownhouse income gender class >>1 30-40 no no medium female good >>2 50-60 yes yes high female good >>3 30-40 yes no high female good >> >> >> >>>credit.toy[[5]]$class >>> >>> >>[1] good poor poor >>Levels: good poor >> >> >>How can I count there are only one class and differennt class. >>I need the result something like >>good class : 1,3,6 >>poor class : 4 >>good and poor class : 2,5 >> >>Thanks in advance. >>Sincerely, Muhammad Subianto >> >>__ >>R-help@stat.math.ethz.ch mailing list >>https://stat.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide! >>http://www.R-project.org/posting-guide.html >> >> >> > > > >-- >Jim Holtman >Cincinnati, OH >+1 513 247 0281 > >What the problem you are trying to solve? > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to convert decimals to fractions
Dear all, Are there any functions to convert decimals to fractions in R? I have the result: > summary(as.factor(complete.ID)) 0 0.0133 0.04 2256488230 0.0667 0.0933 0.107 2342310726 0.133 0.147 0.16 179750163 0.1870.2 0.227 194180 57 0.253 0.267 0.293 1 10 40 0.32 0.333 0.347 45 61117 0.373 62 > How to convert something like this: 0 1/75 3/75 2256488230 5/75 7/75 8/75 2342310726 10/75 11/75 12/75 179750163 14/75 15/75 17/75 194180 57 19/75 20/75 22/75 1 10 40 24/75 25/75 26/75 45 61117 28/75 62 Any suggestions would be appreciated. Thanks you. Best, Muhammad Subianto PS. I found this website: http://www.mindspring.com/~alanh/fracs.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to convert decimals to fractions
On this day 27/01/2006 11:51, Berwin A Turlach wrote: >> library(MASS) >> as.fractions(c(0, 0.0133, 0.04, > 0.0667, 0.0933, 0.107, > 0.133, 0.147, 0.16, > 0.187,0.2, 0.227, > 0.253, 0.267, 0.293, >0.32, 0.333, 0.347, > 0.373)) > > [1] 0 1/75 1/25 1/15 7/75 8/75 2/15 11/75 4/25 14/75 1/5 17/75 > [13] 19/75 4/15 22/75 8/25 1/3 26/75 28/75 > On this day 27/01/2006 11:53, Prof Brian Ripley wrote: > library(MASS) > ?fractions > > help.search("fractions") gets you there. > Many Thanks to Berwin A Turlach and Prof Brian Ripley for your suggestions. > ?fractions > Best regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to convert decimals to fractions
Thanks you for your help. Best wishes, Muhammad Subianto On this day 27/01/2006 12:08, Dimitris Rizopoulos wrote: > if it happens to know the denominator, then a simple approach could > be: > > frac.fun <- function(x, den){ > dec <- seq(0, den) / den > nams <- paste(seq(0, den), den, sep = "/") > sapply(x, function(y) nams[which.min(abs(y - dec))]) > } > ### > frac.fun(c(0, 1, 0.827, .06, 0.266), 75) > > > I hope it helps. > > Best, > Dimitris > > > Dimitris Rizopoulos > Ph.D. Student > Biostatistical Centre > School of Public Health > Catholic University of Leuven > > Address: Kapucijnenvoer 35, Leuven, Belgium > Tel: +32/(0)16/336899 > Fax: +32/(0)16/337015 > Web: http://www.med.kuleuven.be/biostat/ > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > - Original Message - > From: "Muhammad Subianto" <[EMAIL PROTECTED]> > To: > Sent: Friday, January 27, 2006 11:39 AM > Subject: [R] How to convert decimals to fractions > > >> Dear all, >> Are there any functions to convert decimals to fractions in R? >> I have the result: >>> summary(as.factor(complete.ID)) >> 0 0.0133 0.04 >> 2256488230 >> 0.0667 0.0933 0.107 >> 2342310726 >> 0.133 0.147 0.16 >>179750163 >> 0.1870.2 0.227 >>194180 57 >> 0.253 0.267 0.293 >> 1 10 40 >> 0.32 0.333 0.347 >> 45 61117 >> 0.373 >> 62 >> How to convert something like this: >> >> 0 1/75 3/75 >> 2256488230 >> 5/75 7/75 8/75 >> 2342310726 >> 10/75 11/75 12/75 >>179750163 >> 14/75 15/75 17/75 >>194180 57 >> 19/75 20/75 22/75 >> 1 10 40 >> 24/75 25/75 26/75 >> 45 61117 >> 28/75 >> 62 >> >> Any suggestions would be appreciated. Thanks you. >> Best, Muhammad Subianto >> PS. >> I found this website: http://www.mindspring.com/~alanh/fracs.html >> >> __ >> R-help@stat.math.ethz.ch mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide! >> http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] working with fractions
Federico Calboli wrote: > Hi All, > > I am writing a fucntion where I would like to use fractions for all the > (numerous) passages. > > Is there a way of creating an environment *within a fucntion* so that all the > numbers/calculations are fractions? > > Best, > > Fede > > > Maybe like this: > library(MASS) > as.fractions(c(0, 0.15, 0.827, .06, 0.266)) [1] 0 3/20 62/75 1/15 4/15 > Regards, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
[R] expand only one of variable
Dear all, I want to expand only one of variable in data frame and the others variable will be following with the expand variable. Here my toy example: toy.df <- data.frame(size=c(3,1,2,0,3,5,1,0), group=LETTERS[1:8], country=c("Germany","England","Argentina","Mexico","Italy","Brazil","France","Spain"), w=rep(0,8), d=rep(0,8), l=rep(0,8)) toy.df The size variable is the number of expand and signed by positive but size with 0 (zero) must be signed by negative. The result something like: size group country w d l sign 3 A Germany 0 0 0 positive 3 A Germany 0 0 0 positive 3 A Germany 0 0 0 positive 1 B England 0 0 0 positive 2 C Argentina 0 0 0 positive 2 C Argentina 0 0 0 positive 0 DMexico 0 0 0 negative 3 E Italy 0 0 0 positive 3 E Italy 0 0 0 positive 3 E Italy 0 0 0 positive 5 FBrazil 0 0 0 positive 5 FBrazil 0 0 0 positive 5 FBrazil 0 0 0 positive 5 FBrazil 0 0 0 positive 5 FBrazil 0 0 0 positive 1 GFrance 0 0 0 positive 0 H Spain 0 0 0 negative I would be very happy if anyone could help me. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] expanded dataset and random number
Dear all R-users, (My apologies if this subject is wrong) I have dataset: mydat <- as.data.frame( matrix(c(14,0,1,0,1,1, 25,1,1,0,1,1, 5,0,0,1,1,0, 31,1,1,1,1,1, 10,0,0,0,0,1), nrow=5,ncol=6,byrow=TRUE)) dimnames(mydat)[[2]] <-c("size","A","B","C","D","E") > mydat size A B C D E 1 14 0 1 0 1 1 2 25 1 1 0 1 1 35 0 0 1 1 0 4 31 1 1 1 1 1 5 10 0 0 0 0 1 > sum(mydat$size) [1] 85 > where size is number of each row that have this combination of variables. In this dataset I have 85 tuples in expanded dataset. I want to generate random number between 1 and 85. Say, if the first random number is 15, so the number 15 is 1 1 0 1 1 then, if the next random number is 7, then 0 1 0 1 1 then if random number is 79 0 0 0 0 1 random number is 46 1 1 1 1 1 random number is 3 0 1 0 1 1 random number is 28 1 1 0 1 1 So, the result random tuples (order from 6 random number): 0 1 0 1 1 0 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 1 I would be very happy if anyone could help me. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] expanded dataset and random number
Dear all, Per Jensen, thanks for your great help. All methods are very useful. Best, Muhammad Subianto On this day 20/06/2006 22:28, Per Jensen wrote: > A couple of suggestions: > > #First solution > mydatexpanded<-mydat[rep(1:5,mydat[,1]),] > > sampledat<-mydatexpanded[sample(1:85,7),-1] > > #Second solution > > sampledat<-mydat[sample(1:5,size=7,prob=mydat[,1]/85,replace=TRUE),-1] > > Regards > Per Jensen > > On 6/20/06, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > >> >> Dear all R-users, >> (My apologies if this subject is wrong) >> I have dataset: >> mydat <- as.data.frame( >> matrix(c(14,0,1,0,1,1, >> 25,1,1,0,1,1, >> 5,0,0,1,1,0, >> 31,1,1,1,1,1, >> 10,0,0,0,0,1), >> nrow=5,ncol=6,byrow=TRUE)) >> dimnames(mydat)[[2]] <-c("size","A","B","C","D","E") >> > mydat >> size A B C D E >> 1 14 0 1 0 1 1 >> 2 25 1 1 0 1 1 >> 35 0 0 1 1 0 >> 4 31 1 1 1 1 1 >> 5 10 0 0 0 0 1 >> > sum(mydat$size) >> [1] 85 >> > >> >> where size is number of each row that have this combination of >> variables. >> In this dataset I have 85 tuples in expanded dataset. >> I want to generate random number between 1 and 85. >> Say, if the first random number is 15, so the number 15 is >> 1 1 0 1 1 >> then, if the next random number is 7, then >> 0 1 0 1 1 >> >> then if >> random number is 79 >> 0 0 0 0 1 >> random number is 46 >> 1 1 1 1 1 >> random number is 3 >> 0 1 0 1 1 >> random number is 28 >> 1 1 0 1 1 >> >> So, the result random tuples (order from 6 random number): >> 0 1 0 1 1 >> 0 1 0 1 1 >> 1 1 0 1 1 >> 1 1 0 1 1 >> 1 1 1 1 1 >> 0 0 0 0 1 >> >> I would be very happy if anyone could help me. >> Thank you very much in advance. >> Kindly regards, Muhammad Subianto >> >> __ >> R-help@stat.math.ethz.ch mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide! >> http://www.R-project.org/posting-guide.html >> > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Error install rgl package on linux
Dear all, I tried to install rgl package on my linux machine fc5, I got an error. Here I run R as user, $ R > options(repos=c(CRAN="http://cran.at.r-project.org/";)) > install.packages("rgl", > lib="/home/subianto/local/lib/R/library/site-packages", dependencies=TRUE) trying URL 'http://cran.at.r-project.org/src/contrib/rgl_0.67-2.tar.gz' Content type 'application/x-tar' length 567592 bytes opened URL == downloaded 554Kb * Installing *source* package 'rgl' ... checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -E checking for X... libraries , headers checking for libpng-config... yes configure: using libpng-config configure: using libpng dynamic linkage configure: creating ./config.status config.status: creating src/Makevars ** libs g++ -I/usr/lib/R/include -I/usr/lib/R/include -I -DHAVE_PNG_H -I/usr/include/libpng12 -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -c api.cpp -o api.o Disposable.hpp:13: warning: 'struct IDisposeListener' has virtual functions but non-virtual destructor types.h:77: warning: 'class DestroyHandler' has virtual functions but non-virtual destructor gui.hpp:56: warning: 'class gui::WindowImpl' has virtual functions but non-virtual destructor gui.hpp:90: warning: 'class gui::GUIFactory' has virtual functions but non-virtual destructor pixmap.h:39: warning: 'class PixmapFormat' has virtual functions but non-virtual destructor Disposable.hpp:13: warning: 'struct IDisposeListener' has virtual functions but non-virtual destructor gui.hpp:56: warning: 'class gui::WindowImpl' has virtual functions but non-virtual destructor gui.hpp:90: warning: 'class gui::GUIFactory' has virtual functions but non-virtual destructor g++ -shared -L/usr/local/lib -o rgl.so api.o Background.o BBoxDeco.o Color.o device.o devicemanager.o Disposable.o FaceSet.o fps.o geom.o gl2ps.o glgui.o gui.o Light.o LineSet.o LineStripSet.o Material.o math.o osxgui.o osxlib.o par3d.o pixmap.o PointSet.o PrimitiveSet.o QuadSet.o RenderContext.o render.o rglview.o scene.o select.o Shape.o SphereMesh.o SphereSet.o SpriteSet.o String.o Surface.o TextSet.o Texture.o TriangleSet.o types.o Viewpoint.o win32gui.o win32lib.o x11gui.o x11lib.o -L -lX11 -lXext -lGL -lGLU -L/usr/lib -lpng12 -L/usr/lib/R/lib -lR /usr/bin/ld: cannot find -lXext collect2: ld returned 1 exit status make: *** [rgl.so] Error 1 chmod: cannot access `/home/subianto/local/lib/R/library/site-packages/rgl/libs/*': No such file or directory ERROR: compilation failed for package 'rgl' ** Removing '/home/subianto/local/lib/R/library/site-packages/rgl' The downloaded packages are in /tmp/RtmpH3o1qG/downloaded_packages Warning messages: 1: installation of package 'rgl' had non-zero exit status in: install.packages("rgl", lib = "/home/subianto/local/lib/R/library/site-packages", 2: cannot create HTML package index in: tools:::unix.packages.html(.Library) > I think the error about missing devel-libraries on my fc5 but I do not know which libraries are. I apologize for my poor linux knowledge and expertise. Thank you very much. Best, Muhammad Subianto > version _ platform i686-redhat-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) > $ uname -r 2.6.17-1.2145_FC5 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Error install rgl package on linux
On this day 12/07/2006 15:57, Peter Dalgaard wrote: > "Muhammad Subianto" <[EMAIL PROTECTED]> writes: > > >> QuadSet.o RenderContext.o render.o rglview.o scene.o select.o Shape.o >> SphereMesh.o SphereSet.o SpriteSet.o String.o Surface.o TextSet.o >> Texture.o TriangleSet.o types.o Viewpoint.o win32gui.o win32lib.o >> x11gui.o x11lib.o -L -lX11 -lXext -lGL -lGLU -L/usr/lib -lpng12 >> -L/usr/lib/R/lib -lR >> /usr/bin/ld: cannot find -lXext >> collect2: ld returned 1 exit status >> make: *** [rgl.so] Error 1 > > ... > >> I think the error about missing devel-libraries on my fc5 but I do not >> know which libraries are. I apologize for my poor linux knowledge and >> expertise. Thank you very much. > > I have > > [EMAIL PROTECTED] R]$ locate Xext > /usr/include/X11/extensions/Xext.h > /usr/include/X11/extensions/panoramiXext.h > /usr/lib/libXext.so > /usr/lib/libXext.so.6 > /usr/lib/libXext.so.6.4.0 > /usr/share/doc/libXext-1.0.0 > . > > > [EMAIL PROTECTED] R]$ rpm -qf `locate Xext` > xorg-x11-proto-devel-7.0-6 > xorg-x11-proto-devel-7.0-6 > libXext-devel-1.0.0-3.2 > libXext-1.0.0-3.2 > > > In general, if you get an error about a missing -lfoo, installing RPMs > for libfoo and libfoo-devel is the first thing to try. > > > Thank you for giving me so much of your time to provide an explanation of installing RPMs. After I installed "libXext-devel" and then > options(repos=c(CRAN="http://cran.at.r-project.org/";)) > install.packages("rgl", > lib="/home/subianto/local/lib/R/library/site-packages", dependencies=TRUE) Yes, it works perfectly. Thanks a lot, to Peter Dalgaard. Sincerely, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Listing all of combinations
On this day 14/07/2006 15:35, miao wrote: > Dear All: > > I want to list all of combination among (a,b,c,d,e,f,g,h). I try to use > lp<-ist(A=c(a,b,c,d,e,f,g,h),B=(a,b,c,d,e,f,g,h)etc.).and then use > expand.grid(p). this does not work for the same vector A,B... > > Anyone had this experince? > > >Thanks! > >Xin > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > Try this below: A <- letters[1:8] B <- letters[1:8] lp<-list(A,B) expand.grid(lp) Best, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] install.packages for local zip files
On 7/16/06, Daniel Gatti <[EMAIL PROTECTED]> wrote: > O/S: Linux > R version : 2.2.1 > > The R server doesn't have http internet access. And the sys admins will > not install the R libraries that I requested. So I have downloaded the > packages that I want to intall and have moved them into my home > directory on the server. These are a series of *.tar.gz files. I want > to install the R libraries in my home directory, but I can't get it to > work. According to the install.packages documentation : > > install.packages(pkgs, lib, repos = getOption("repos"), contriburl = > contrib.url(repos, type), method, available = NULL, destdir = NULL, > installWithVers = FALSE, dependencies = FALSE, type = getOption("pkgType")) > > repos: character vector, the base URL(s) of the repositories to use, >i.e., Can be 'NULL' to install from local '.tar.gz' files. > > contriburl: URL(s) of the contrib section of the repositories. .. >Can be 'NULL' to install from local '.tar.gz' files. > > > pkgs: character vector of the short names of packages/bundles whose > current versions should be downloaded from the repositories. > If 'repos = NULL', a character vector of file paths of > '.tar.gz' files. These can be source archives or binary > package/bundle archive files (as created by 'R CMD build > --binary'). .. > > lib: character vector giving the library directories where to install > the packages. Recycled as needed. > > So I have issued a command like this: > > > install.packages(pkgs="~/Rdownloads/hgug4112a_1.12.0.tar.gz", lib = > "~/Rlib", repos=NULL, contriburl=NULL) > > Warning in download.packages(pkgs, destdir = tmpd, available = > available, : > no package '~/Rdownloads/hgug4112a_1.12.0.tar.gz' at the > repositories > > As far as I can tell, I've given it the full path to the zip file, the > directory in which to install the library and I've set the repository > path to 'NULL' to indicate that I'm installing from an already > downloaded zip file. But I'm missing something. Any ideas? > > Thanks, > Dan > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > Put your packages, for example, in directory "/dir/of/pkgs" library(tools) write_PACKAGES("/dir/of/pkgs") and the package will be installed to "/dir/of/R/libs" install.packages("NameOfPkgs", lib="/dir/of/R/libs", repos=NULL, dependencies=TRUE, contriburl="file:dir/of/pkgs") Best, Muhammad Subianto __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plain shading (not residuals) in mosaic plot
Maybe like this: mosaic(allmorph, direction = "v", pop = FALSE, gp=gpar(fill=c(grey(0.8),grey(0.4)))) Best, Muhammad Subianto On 7/19/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > If you look at ?mosaic the ... argument says it gets passed to strucplot and > looking at ?strucplot we see it accepts a gp= arg so try this (same > as your plus gp= arg): > > cols <- c(grey(0.8),grey(0.4)) > mosaic(allmorph, direction = "v", pop = FALSE, gp = list(col = cols)) > > On 7/19/06, Kie Zuraw <[EMAIL PROTECTED]> wrote: > > Hello. I've been using R for a couple of months and enjoying it a lot. > > This is my first post to R-help. > > > > I'm using the vcd package to make mosaic plots with labels on the tiles > > indicating the number of items in each cell. > > > > For example, I've made this plot: > > > > > > > allmorph<-structure(c(10, 26, 17, 100, 70, 97, 253, 430, 185, 177, > > > 25, 1), .Dim = as.integer(c(6, 2)), .Dimnames = > > > structure(list(Stem.initial.obstruent = c("p", "t,s", > > > "k","b","d","g"),Subst.behavior=c("unsubstituted","substituted")), > > > .Names = c("Stem-initial obstruent","Behavior according to > > > dictionary")), class = "table") > > > mosaic(allmorph,direction="v",pop=FALSE) > > > labeling_cells(text=allmorphs,margin=0)(allmorph) > > > > > > So far so good. What I can't figure out how to do--after searching > > through the vcd documentation > > (http://cran.r-project.org/doc/packages/vcd.pdf), Googling, and > > checking the r-help archive--is how to shade the tiles according to > > their values for the variables rather than to reflect residuals. That > > is, I want all the tiles at the bottom, whose value for the x-axis > > variable is "substituted", to be dark grey, and those at the top, in > > the "unsubstituted" category, to be light grey. > > > > I know how to do it with mosaicplot(): > > > > > mosaicplot(morphs3,color=c(grey(0.8),grey(0.4))) > > > > ...but this doesn't work with mosaic(): the command > > "mosaic(morphs3,color=c(grey(0.8),grey(0.4)))" yields a plot with all > > tiles the same color. And conversely, I can't find a way to use > > mosaicplot() and add numeric labels to the tiles--without much hope of > > success, I tried combining mosaicplot() with labeling_cells(), but, > > unsurprisingly, it didn't work: > > > > > mosaicplot(morphs3,color=c(grey(0.8),grey(0.4)),pop=FALSE) > > Warning message: > > extra argument(s) 'pop' will be disregarded in: > > mosaicplot.default(morphs3, color = c(grey(0.8), grey(0.4)), > > > labeling_cells(text=morphs3,margin=0)(morphs3) > > Error in downViewport.vpPath(vpPathDirect(name), strict, recording = > > recording) :Viewport 'cell:Stem-initial obstruent=p,Behavior > > according to dictionary=unsubstituted' was not found > > > > > > Does anyone know how to get both the shading I want and the labels I > > want, whether with mosaic(), with mosaicplot(), or in some other way? > > > > Thanks for your attention. > > > > -Kie Zuraw > > > > __ > > R-help@stat.math.ethz.ch 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. > > > > __ > R-help@stat.math.ethz.ch 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. > __ R-help@stat.math.ethz.ch 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.
Re: [R] plain shading (not residuals) in mosaic plot
Maybe like this: mosaic(allmorph, direction = "v", pop = FALSE, gp=gpar(fill=c(grey(0.8),grey(0.4)))) Best, Muhammad Subianto On 7/19/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > If you look at ?mosaic the ... argument says it gets passed to strucplot and > looking at ?strucplot we see it accepts a gp= arg so try this (same > as your plus gp= arg): > > cols <- c(grey(0.8),grey(0.4)) > mosaic(allmorph, direction = "v", pop = FALSE, gp = list(col = cols)) > > On 7/19/06, Kie Zuraw <[EMAIL PROTECTED]> wrote: > > Hello. I've been using R for a couple of months and enjoying it a lot. > > This is my first post to R-help. > > > > I'm using the vcd package to make mosaic plots with labels on the tiles > > indicating the number of items in each cell. > > > > For example, I've made this plot: > > > > > > > allmorph<-structure(c(10, 26, 17, 100, 70, 97, 253, 430, 185, 177, > > > 25, 1), .Dim = as.integer(c(6, 2)), .Dimnames = > > > structure(list(Stem.initial.obstruent = c("p", "t,s", > > > "k","b","d","g"),Subst.behavior=c("unsubstituted","substituted")), > > > .Names = c("Stem-initial obstruent","Behavior according to > > > dictionary")), class = "table") > > > mosaic(allmorph,direction="v",pop=FALSE) > > > labeling_cells(text=allmorphs,margin=0)(allmorph) > > > > > > So far so good. What I can't figure out how to do--after searching > > through the vcd documentation > > (http://cran.r-project.org/doc/packages/vcd.pdf), Googling, and > > checking the r-help archive--is how to shade the tiles according to > > their values for the variables rather than to reflect residuals. That > > is, I want all the tiles at the bottom, whose value for the x-axis > > variable is "substituted", to be dark grey, and those at the top, in > > the "unsubstituted" category, to be light grey. > > > > I know how to do it with mosaicplot(): > > > > > mosaicplot(morphs3,color=c(grey(0.8),grey(0.4))) > > > > ...but this doesn't work with mosaic(): the command > > "mosaic(morphs3,color=c(grey(0.8),grey(0.4)))" yields a plot with all > > tiles the same color. And conversely, I can't find a way to use > > mosaicplot() and add numeric labels to the tiles--without much hope of > > success, I tried combining mosaicplot() with labeling_cells(), but, > > unsurprisingly, it didn't work: > > > > > mosaicplot(morphs3,color=c(grey(0.8),grey(0.4)),pop=FALSE) > > Warning message: > > extra argument(s) 'pop' will be disregarded in: > > mosaicplot.default(morphs3, color = c(grey(0.8), grey(0.4)), > > > labeling_cells(text=morphs3,margin=0)(morphs3) > > Error in downViewport.vpPath(vpPathDirect(name), strict, recording = > > recording) :Viewport 'cell:Stem-initial obstruent=p,Behavior > > according to dictionary=unsubstituted' was not found > > > > > > Does anyone know how to get both the shading I want and the labels I > > want, whether with mosaic(), with mosaicplot(), or in some other way? > > > > Thanks for your attention. > > > > -Kie Zuraw > > > > __ > > R-help@stat.math.ethz.ch 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. > > > > __ > R-help@stat.math.ethz.ch 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. > __ R-help@stat.math.ethz.ch 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.
[R] convert decimals to fractions - sorted
Dear all, Based on my question a few months ago https://stat.ethz.ch/pipermail/r-help/2006-January/086952.html and solved with https://stat.ethz.ch/pipermail/r-help/2006-January/086955.html https://stat.ethz.ch/pipermail/r-help/2006-January/086956.html and from https://stat.ethz.ch/pipermail/r-help/2006-January/086958.html frac.fun <- function(x, den){ dec <- seq(0, den) / den nams <- paste(seq(0, den), den, sep = "/") sapply(x, function(y) nams[which.min(abs(y - dec))]) } ### frac.fun(c(0, 1, 0.827, .06, 0.266), 75) Now, I have a dataset something like this: a <-"1 0 1 0.095238095238095 1 0.214285714285714 -1 0.5 1 0.309523809523810 -1 0.0476190476190476 1 0.404761904761905 1 0.119047619047619 -1 0.214285714285714 -1 0.309523809523810 1 0 1 0 1 0.404761904761905 1 0.095238095238095 1 0.047619047619047 1 0.380952380952381 1 0.214285714285714 1 0.523809523809524 1 0 1 0.095238095238095" First, I make it as fractions and then sorted. I have played around to make it sort, but it didn't succes. df <- read.table(textConnection(a)) library(MASS) as.fractions(as.numeric(df[,2])) cbind(table(df[,2], df[,1]), summary(as.factor(df[,2]))) table(frac.fun(as.numeric(df[,2]),42), df[,1]) > table(frac.fun(as.numeric(df[,2]),42), df[,1]) -1 1 0/42 0 4 13/42 1 1 16/42 0 1 17/42 0 2 21/42 1 0 22/42 0 1 2/42 1 1 4/42 0 3 5/42 0 1 9/42 1 2 > How to make the result as sort (to increase) like this, -1 1 0/42 0 4 2/42 1 1 4/42 0 3 5/42 0 1 9/42 1 2 13/42 1 1 16/42 0 1 17/42 0 2 21/42 1 0 22/42 0 1 Thank's for any help. Best, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
Re: [R] convert decimals to fractions - sorted
Dear all, Thanks for your help. I played with you suggest and still didn't sort (summary) which I need. > t(table(at2[sort.order,c(1,3)])) V1 jeebee -1 1 0 0 4 11/21 0 1 1/21 0 1/21 1 1 13/42 1 1 17/42 0 2 2/21 0 3 3/14 1 2 5/42 0 1 8/21 0 1 > I need the result summary (order) like, -1 1 0/42 0 4 2/42 1 1 4/42 0 3 5/42 0 1 9/42 1 2 13/42 1 1 16/42 0 1 17/42 0 2 21/42 1 0 22/42 0 1 Thanks very much for any suggestions. Groeten & Regards, Muhammad Subianto On 7/26/06, JeeBee <[EMAIL PROTECTED]> wrote: > > Hi Muhammad, > > How about this? > > at <- read.table(textConnection(a)) > at2 <- cbind(at, jeebee=as.character(as.fractions(as.numeric(at[,2] > > sort.order <- order(at2$V2) > > at2[sort.order,] > at2[sort.order,c(1,3)] > > JeeBee. > > __ > R-help@stat.math.ethz.ch 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. > On 7/25/06, Muhammad Subianto <[EMAIL PROTECTED]> wrote: > Dear all, > Based on my question a few months ago > https://stat.ethz.ch/pipermail/r-help/2006-January/086952.html > and solved with > https://stat.ethz.ch/pipermail/r-help/2006-January/086955.html > https://stat.ethz.ch/pipermail/r-help/2006-January/086956.html > and from > https://stat.ethz.ch/pipermail/r-help/2006-January/086958.html > > frac.fun <- function(x, den){ > dec <- seq(0, den) / den > nams <- paste(seq(0, den), den, sep = "/") > sapply(x, function(y) nams[which.min(abs(y - dec))]) > } > ### > frac.fun(c(0, 1, 0.827, .06, 0.266), 75) > > Now, I have a dataset something like this: > > a <-"1 0 > 1 0.095238095238095 > 1 0.214285714285714 >-1 0.5 > 1 0.309523809523810 >-1 0.0476190476190476 > 1 0.404761904761905 > 1 0.119047619047619 >-1 0.214285714285714 >-1 0.309523809523810 > 1 0 > 1 0 > 1 0.404761904761905 > 1 0.095238095238095 > 1 0.047619047619047 > 1 0.380952380952381 > 1 0.214285714285714 > 1 0.523809523809524 > 1 0 > 1 0.095238095238095" > > First, I make it as fractions and then sorted. > I have played around to make it sort, but it didn't succes. > > df <- read.table(textConnection(a)) > library(MASS) > as.fractions(as.numeric(df[,2])) > cbind(table(df[,2], df[,1]), summary(as.factor(df[,2]))) > table(frac.fun(as.numeric(df[,2]),42), df[,1]) > > table(frac.fun(as.numeric(df[,2]),42), df[,1]) > > -1 1 > 0/42 0 4 > 13/42 1 1 > 16/42 0 1 > 17/42 0 2 > 21/42 1 0 > 22/42 0 1 > 2/42 1 1 > 4/42 0 3 > 5/42 0 1 > 9/42 1 2 > > > > How to make the result as sort (to increase) like this, > > -1 1 > 0/42 0 4 > 2/42 1 1 > 4/42 0 3 > 5/42 0 1 > 9/42 1 2 > 13/42 1 1 > 16/42 0 1 > 17/42 0 2 > 21/42 1 0 > 22/42 0 1 > > Thank's for any help. > > Best, Muhammad Subianto > __ R-help@stat.math.ethz.ch 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.
Re: [R] convert decimals to fractions - sorted
Dear JeeBee and all, It is nice. Thanks you very much. I must learn much more about ?as.fractions, ?as.numeric, ?as.character and ?table functions. Best wishes, Muhammad Subianto On 7/28/06, JeeBee <[EMAIL PROTECTED]> wrote: > > Ah I see, I did not read your story well enough. > You want to sort after applying table() > Well, the idea I suggested was to keep the real numbers in, > because the fractions are sorted as characters strings (alphabetically), > which is not what you want. So, now I suggest the following: > > # First apply table() > tmp1 <- as.data.frame(table(df)) > > # Note that table() turned your numeric data into factors, > # this might not be a handy approach, anyways, it is possible I guess. > # You have to convert back using as.numeric(as.character(tmp1$V2)) > # or, more efficiently, as.numeric(levels(tmp1$V2))[tmp1$V2] > > # Add the column with the fractions > tmp2 <- cbind(tmp1, > fracs=as.character(as.fractions(as.numeric(as.character(tmp1$V2) > > # Finally hide that sort colum if you want > > ( tmp2[-2] ) > > # Everybody happy? > > JeeBee > > __ > R-help@stat.math.ethz.ch 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. > __ R-help@stat.math.ethz.ch 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.
[R] Take random sample from class variable
Dear all, Suppose I have a dataset like below, then I take for example, 100 random sample "class" variable where contains "yes" and "no" respectively, 70% and 30%. I need a new 100 random sample from mydat dataset, but I can't get the result. Thanks you very much for any helps. Best, Muhammad Subianto mydat <- data.frame(size=c(30,12,15,10,12,12,25,30,20,14), A=c(0,1,0,1,0,1,1,1,0,0), B=c(1,1,0,1,0,1,1,0,0,1), C=c(0,0,1,1,0,0,1,1,0,0), D=c(1,1,1,1,0,1,0,0,1,1), E=c(1,1,0,1,1,1,1,1,1,0), Class=c("yes","yes","no","yes","yes","no","yes","no","yes","yes")) mydat # Maximal data from dataset max.size <- sum(mydat$size);max.size # I need sample random nof.sample <- 100 set.seed(123) sample.class <- sample(c("yes","no"), nof.sample, prob=c(.7, .3), replace=TRUE) sample.class sampledat.class <- mydat[sample.class,] sampledat.class __ R-help@stat.math.ethz.ch 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.
[R] How to find AUC in SVM (kernlab package)
Dear all, I was wondering if someone can help me. I am learning SVM for classification in my research with kernlab package. I want to know about classification performance using Area Under Curve (AUC). I know ROCR package can do this job but I found all example in ROCR package have include prediction, for example, ROCR.hiv {ROCR}. My problem is how to produce prediction in SVM and to find AUC. Here is a simple example: library(MASS) library(kernlab) library(ROCR) pimamodel <- ksvm(type ~ .,data=Pima.tr,type="C-svc",C=10,prob.model=TRUE) pimamodel fitted(pimamodel) pima.pred <- predict(pimamodel, Pima.te[,-8], type="probabilities") pima.pred # try to find AUC #predid.no <- prediction(pima.pred[,1], Pima.te[,8]) #predid.yes <- prediction(pima.pred[,2], Pima.te[,8]) predid <- prediction(pima.pred, Pima.te[,8]) perfid <- performance(predid,"tpr","fpr") perfid.auc <- performance(predid,"auc") perfid.auc Thank you very much for your help. Best wishes, Muhammad Subianto __ R-help@stat.math.ethz.ch 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.
Re: [R] How to find AUC in SVM (kernlab package)
On this day 11/24/2006 05:03 PM, Amir Safari wrote: > Hi > you need predict.ksvm() function. > Yes, like this is below I do to predict (kernlab package, http://www.jstatsoft.org/v11/i09/v11i09.pdf): pima.pred <- predict(pimamodel, Pima.te[,-8], type="probabilities") pima.pred My problems is how to find AUC (with ROCR package, or other ROC functions) from predict above. Regards, Muhammad Subianto > for more information see The kernlab package here: > http://lib.stat.cmu.edu/R/CRAN/doc/packages/kernlab.pdf > > cheers, > Amir > > > */Muhammad Subianto <[EMAIL PROTECTED]>/* wrote: > > Dear all, > I was wondering if someone can help me. I am learning SVM for > classification in my research with kernlab package. I want to know > about > classification performance using Area Under Curve (AUC). I know ROCR > package can do this job but I found all example in ROCR package have > include prediction, for example, ROCR.hiv {ROCR}. My problem is > how to > produce prediction in SVM and to find AUC. > > Here is a simple example: > > library(MASS) > library(kernlab) > library(ROCR) > > pimamodel <- ksvm(type ~ > .,data=Pima.tr,type="C-svc",C=10,prob.model=TRUE) > pimamodel > fitted(pimamodel) > > pima.pred <- predict(pimamodel, Pima.te[,-8], type="probabilities") > pima.pred > > # try to find AUC > #predid.no <- prediction(pima.pred[,1], Pima.te[,8]) > #predid.yes <- prediction(pima.pred[,2], Pima.te[,8]) > predid <- prediction(pima.pred, Pima.te[,8]) > perfid <- performance(predid,"tpr","fpr") > perfid.auc <- performance(predid,"auc") > perfid.auc > > Thank you very much for your help. > > Best wishes, Muhammad Subianto > > __ > R-help@stat.math.ethz.ch 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. > > > > Cheap Talk? Check out > <http://us.rd.yahoo.com/mail_us/taglines/postman8/*http://us.rd.yahoo.com/evt=39663/*http://voice.yahoo.com> > > Yahoo! Messenger's low PC-to-Phone call rates. __ R-help@stat.math.ethz.ch 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.
[R] Make many barplot into one plot
Dear all, ## I have 4 tables like this: satu <- array(c(5,15,20,68,29,54,84,119), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond"))) dua <- array(c(50,105,30,8,29,25,84,9), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond"))) tiga <- array(c(9,16,26,68,12,4,84,12), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond"))) empat <- array(c(25,13,50,78,19,34,84,101), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond"))) ## with barplot I can make a plot for each table: barplot(satu, beside=TRUE, legend.text=rownames(satu), ylim = c(0, max(colSums(satu)) * 1.2)) x11() barplot(dua, beside=TRUE, legend.text=rownames(dua), ylim = c(0, max(colSums(dua)) * 1.2)) x11() barplot(tiga, beside=TRUE, legend.text=rownames(tiga), ylim = c(0, max(colSums(tiga)) * 1.2)) x11() barplot(empat, beside=TRUE, legend.text=rownames(empat), ylim = c(0, max(colSums(empat)) * 1.2)) ## I can make all barplot above into one plot with x11(width=11,height=8) ## Make a plot with 2 rows and 2 columns oldpar <- par(mfrow=c(2,2), barplot(above) par(oldpar) ## Are there any functions to make all barplot above into one plot? ## I would like to produce barplot like: | | | | | | | | | | | | | | | | | | |pos|neg|pos|neg|pos|neg|pos|neg| |pos|neg|pos|neg| ... | | | | | | | | | | | | | | - satu dua tiga empatsatudua ... black blond I would be grateful if anybody could help me. Thank you very much. Muhammad Subianto __ R-help@stat.math.ethz.ch 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.