[R] Correlation
Dear all, I have written the following code for correlation calculations. I want to create a new matrix from corData) with correlation more than 0.5 only and the rest of the columns should be removed. How can I do it? set.seed(1234) data<-matrix(rnorm(100),nrow=10) data[,1]<-100*(data[,2]+data[,5]+data[,9]) corData<-cor(data) Thanks a lot Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] average and median values for each of the class
Dear all, I have a matrix (dimension, 16 x 12) where 2nd column represents class (1,1,1,1,1,2,2,2, etc) information. I want to estimate average and median values for each of the class and add this information as a row at end of the each classes. for example: dput(dat) structure(list(class = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L), name1 = c(2.554923977, 2.371586762, 2.497293431, 2.464827875, 2.981934845, 2.228995664, 2.099640729, 1.900314302, 2.630005966, 2.632590262, 2.581887814, 2.408797563, 2.098761103, 3.070460716, 1.436980716, 1.645121806), name2 = c(1.297412278, 1.104804244, 1.30621114, 1.126009533, 1.466740841, 1.012041118, 0.923466541, 0.840575023, 1.285530176, 1.041909333, 1.194917856, 1.085015826, 1.047492703, 1.587558217, 0.593340012, 0.723630088 ), name3 = c(0.587160798, 0.596127884, 0.623760721, 0.549016135, 0.686642084, 0.487523394, 0.458620467, 0.397974913, 0.615928976, 0.546005649, 0.657383069, 0.546613129, 0.476503461, 0.749062102, 0.304160587, 0.29037358), name4 = c(2.833441759, 2.713374426, 2.532626548, 2.409093102, 3.014912721, 2.113507947, 2.017291324, 1.667744912, 2.602560666, 2.31649643, 2.761204809, 2.433963493, 2.229911767, 3.191646399, 1.269919241, 1.387479858), name5 = c(2.172365295, 1.955695471, 2.141072829, 1.975743278, 2.377018372, 1.791300389, 1.669079382, 1.500209628, 2.164401874, 1.830038378, 2.106750025, 1.92888294, 1.707217549, 2.585082653, 1.114841754, 1.315712452 ), name6 = c(0.715129844, 0.688186262, 0.70133748, 0.709362008, 0.712145174, 0.563593885, 0.532109761, 0.472197304, 0.690165016, 0.65635473, 0.615835066, 0.64310098, 0.562974891, 0.900622255, 0.408546784, 0.416284408), name7 = c(1.995505133, 1.860095899, 1.843151597, 1.709861774, 2.155993511, 1.506409746, 1.315405587, 1.234544153, 1.96629927, 1.74879757, 1.93994009, 1.660173854, 1.556735295, 2.355723318, 0.866634243, 1.013367677), name8 = c(0.275484997, 0.233856392, 0.294021245, 0.315504347, 0.251906585, 0.250263636, 0.348599173, 0.273806933, 0.32067937, 0.278581115, 0.293726291, 0.308350808, 0.201297444, 0.351927886, 0.204230625, 0.185681471 ), name9 = c(2.461066627, 2.210756164, 2.289047888, 2.253988252, 2.668184733, 1.911697836, 1.793443775, 1.560027186, 2.36941155, 1.96191, 2.391501376, 2.002215107, 1.932144233, 2.73705052, 1.15580754, 1.807697999), name10 = c(0.723025351, 0.613147422, 0.805399925, 0.65651577, 0.779389048, 0.54260459, 0.492283542, 0.507969501, 0.749700016, 0.644231327, 0.810319215, 0.620331891, 0.600240557, 0.884775748, 0.40006142, 0.391661912), name11 = c(0.308565619, 0.453808281, 0.363716904, 0.376332596, 0.324998876, 0.361013073, 0.430744786, 0.468818055, 0.166072668, 0.369262627, 0.297666411, 0.256091173, 0.123021464, 0.308188684, 0.646436241, 0.722972632 )), .Names = c("class", "name1", "name2", "name3", "name4", "name5", "name6", "name7", "name8", "name9", "name10", "name11"), class = "data.frame", row.names = c("ara1", "ara2", "ara3", "ara4", "ara5", "ara6", "ara7", "ara8", "ara9", "ara10", "ara11", "ara12", "ara13", "ara14", "ara15", "ara16" )) I wrote this: avg<-as.data.frame(aggregate(dat[,2:dim(dat)[2]], dat["class"], function(x) mean(x,na.rm=T)) ) med<-as.data.frame(aggregate(dat[,2:dim(dat)[2]], dat["class"], function(x) median(x,na.rm=T)) ) # avg # classname1 name2 name3name4name5 name6name7 name#8name9name10name11 #1 1 2.574113 1.2602356 0.6085415 2.700690 2.124379 0.7052322 1.912922 #0.2741547 2.376609 0.7154955 0.3654845 #2 2 2.214739 1.0154032 0.4900119 2.100276 1.781248 0.5645165 1.505665 #0.2983373 1.908645 0.5731394 0.3566621 #3 3 2.541092 1.1072810 0.589 2.503888 1.955224 0.6384303 1.782971 #0.2935527 2.118543 0.6916275 0.3076734 #4 4 2.202068 1.0761303 0.5099087 2.230492 1.802381 0.6240480 1.593031 #0.2524853 1.941667 0.6283592 0.3592155 #5 5 1.645122 0.7236301 0.2903736 1.387480 1.315712 0.4162844 1.013368 #0.1856815 1.807698 0.3916619 0.7229726 #> med # classname1 name2 name3name4name5 name6name7 name#8name9name10name11 #1 1 2.497293 1.2974123 0.5961279 2.713374 2.141073 0.7093620 1.860096 #0.2754850 2.289048 0.7230254 0.3637169 #2 2 2.164318 0.9677538 0.4730719 2.065400 1.730190 0.5478518 1.410908 #0.2972432 1.852571 0.5252870 0.3958789 #3 3 2.581888 1.0850158 0.5466131 2.433963 1.928883 0.6431010 1.748798 #0.2937263 2.002215 0.6442313 0.2976664 #4 4 2.098761 1.0474927 0.4765035 2.229912 1.707218 0.5629749 1.556735 #0.2042306 1.932144 0.6002406 0.3081887 #5 5 1.645122 0.7236301 0.2903736 1.387480 1.315712 0.4162844 1.013368 #0.1856815 1.807698 0.3916619 0.7229726 But I do not know how can I add this information in the original data? For example, for class 1, the output will look like this: dput(res1) structure(list(class = c(1L, 1L, 1L, 1L, 1L, 1L, 1L), name1 = c(2.554923977, 2.371586762, 2.497293431, 2.464827875, 2.98193
Re: [R] Formatting with strings
Many thanks Jim. It works for my large data set! Best Regards Nico On Wed, Apr 23, 2014 at 1:45 PM, jim holtman wrote: > try this: > > > x <- readLines(textConnection("---CLUSTER 1 --- > + 3 > + 4 > + 5 > + 6 > + ---CLUSTER 2 --- > + 9 > + 10 > + 8 > + 11")) > > > > # create a list of where the 'clusters' are > > clust <- c(grep("CLUSTER", x), length(x) + 1L) > > > > # get size of each cluster > > clustSize <- diff(clust) - 1L > > > > # get cluster number > > clustNum <- gsub("[^0-9]+", "", x[grep("CLUSTER", x)]) > > > > result <- do.call(rbind, lapply(seq(length(clustNum)), function(.cl){ > + cbind(Object = x[seq(clust[.cl] + 1L, length = clustSize[.cl])] > + , Cluster = .cl > + ) > + })) > > > > result > Object Cluster > [1,] "3""1" > [2,] "4""1" > [3,] "5""1" > [4,] "6""1" > [5,] "9""2" > [6,] "10" "2" > [7,] "8""2" > [8,] "11" "2" > > > > > > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > Tell me what you want to do, not how you want to do it. > > > On Wed, Apr 23, 2014 at 5:58 AM, Nico Met wrote: > >> Dear all, I have object where I stored clusters in the following manner: >> >> ---CLUSTER 1 --- >> 3 >> 4 >> 5 >> 6 >> ---CLUSTER 2 --- >> 9 >> 10 >> 8 >> 11 >> >> Now want to format the data in the following way: >> >> Object Cluster >> 31 >> 41 >> 51 >> 61 >> 9 2 >> 10 2 >> 8 2 >> 11 2 >> >> >> How can I do this in R? >> >> Thanks >> >> Nico >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Formatting with strings
Dear all, I have object where I stored clusters in the following manner: ---CLUSTER 1 --- 3 4 5 6 ---CLUSTER 2 --- 9 10 8 11 Now want to format the data in the following way: Object Cluster 31 41 51 61 9 2 10 2 8 2 11 2 How can I do this in R? Thanks Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Column value comparison and colouring
Dear all, I have a big matrix, where I want to compare, one element of a vector with many others and clear them. For example: In column sil compare elements with other columns (0.734)>-1.0770 in 3rd column, so, color them bold else color them bold red For example: > dput(test) structure(list(Class = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L), sil = c(0.734, 0.734, 0.734, 0.734, 0.734, -0.03, -0.03, -0.03), M201.1637T.1 = c(-1.077019059, -1.025923945, -2.025907674, -1.223001413, -1.547348898, -0.376842603, -1.33495095, -0.486811653), M203.1794T.1 = c(-0.884899777, -0.878305283, -1.910526051, -1.446826543, -1.950515819, -0.192865129, -1.669691644, -0.636095942), M205.1950T.1 = c(-1.307163965, -1.022407192, -2.050283307, -1.508604131, -1.710170605, -0.197410826, -1.547129558, -0.780189201 ), M207.2107T.1 = c(-1.378614081, -0.950293267, -1.714837198, -1.827195011, -1.629677288, -0.064343778, -1.598304259, -0.502002575 )), .Names = c("Class", "sil", "M201.1637T.1", "M203.1794T.1", "M205.1950T.1", "M207.2107T.1"), class = "data.frame", row.names = c("52T_D06_19_42", "500030X_B03_19_15", "500059R_G09_19_81", "500061V_H02_13_86", "500078W_D10_6_46", "500082M_D05_18_41", "500105S_B09_15_21", "500120W_B04_19_16") Thanks in advance Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix of mean values
Dear Arun, thanks for the solution. however, for my data I am getting this warning message Warning messages: 1: In mean.default(.value[0], ...) : argument is not numeric or logical: returning NA what can be the cause of it? Regards Nico On Tue, Oct 8, 2013 at 4:56 PM, arun wrote: > To make it matrix: > > > row.names(res)<- res[,1] > res1<- as.matrix(res[,-1]) > A.K. > > > > - Original Message - > From: arun > To: Nico Met > Cc: R help > Sent: Tuesday, October 8, 2013 10:54 AM > Subject: Re: [R] matrix of mean values > > Try: > > d1$value<-as.numeric(gsub(",","",as.character(d1$value))) > library(reshape2) > res <- dcast(d1,loc~variables,value.var="value",mean) > A.K. > > > > - Original Message - > From: Nico Met > To: R help > Cc: > Sent: Tuesday, October 8, 2013 10:47 AM > Subject: [R] matrix of mean values > > Dear all, I have a data set where I want to make a matrix of the mean > values using 3rd column (value). Where rows are unique loc and columns > would be variables. If there is one observation or no observation just > use NA. > > > > > dput(d1) > > structure(list(loc = structure(c(6L, 9L, 9L, 9L, 9L, 4L, 4L, > > 4L, 4L, 4L, 4L, 13L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 7L, > > 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 10L, > > 10L, 10L, 10L, 10L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 1L, > > 3L, 3L, 3L, 2L), .Label = c("AX09_126", "AX09_628", "AX09_924", > > "IALA08_3299", "JA08_246", "JA08_3299", "JA08_408", "JE08_246", > > "JE08_3299", "JE08_408", "NO08_246", "NO08_408", "PP08_3299"), class = > "factor"), > > variables = structure(c(5L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, > > 7L, 7L, 7L, 7L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 3L, 3L, > > 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 1L, 5L, 5L, 5L, 6L, 6L, 7L, > > 7L, 7L, 7L, 7L, 7L, 7L, 3L, 7L, 4L, 4L, 4L, 7L, 7L, 7L, 7L > > ), .Label = c("i", "r", "s", "t", "x", "y", "z"), class = "factor"), > > value = structure(c(1L, 21L, 2L, 1L, 30L, 32L, 4L, 32L, 5L, > > 20L, 5L, 1L, 24L, 12L, 26L, 24L, 12L, 15L, 26L, 14L, 15L, > > 23L, 13L, 11L, 23L, 25L, 23L, 6L, 7L, 3L, 8L, 19L, 3L, 19L, > > 28L, 16L, 18L, 18L, 17L, 31L, 29L, 10L, 27L, 22L, 9L, 22L, > > 22L, 9L, 9L, 35L, 33L, 33L, 33L, 34L), .Label = c("0", "0,", > > "142,1", "1506,6", "1520,4", "170,36", "18,6185", > > "19,2933", "20,2125", "20,7423", "225,94", "23,2245", "24,3526", > > "24,3685", "24,4593", "242,84", "25,7422", "26,34", "26,5989", > > "30,6284", "36,6608", "39,913", "41,4933", "43,9104", > > "47,1241", "49,3467", "49,5715", "50,0037", "50,7974", "53,6667", > > "56,2778", "76", "76,5", "77,6667", "82"), class = "factor")), .Names = > c("loc", > > "variables", "value"), class = "data.frame", row.names = c(NA, > > -54L)) > > > > Thanks > > > > Nico > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] matrix of mean values
Dear all, I have a data set where I want to make a matrix of the mean values using 3rd column (value). Where rows are unique loc and columns would be variables. If there is one observation or no observation just use NA. > dput(d1) structure(list(loc = structure(c(6L, 9L, 9L, 9L, 9L, 4L, 4L, 4L, 4L, 4L, 4L, 13L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 1L, 3L, 3L, 3L, 2L), .Label = c("AX09_126", "AX09_628", "AX09_924", "IALA08_3299", "JA08_246", "JA08_3299", "JA08_408", "JE08_246", "JE08_3299", "JE08_408", "NO08_246", "NO08_408", "PP08_3299"), class = "factor"), variables = structure(c(5L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 7L, 7L, 7L, 7L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 1L, 5L, 5L, 5L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 3L, 7L, 4L, 4L, 4L, 7L, 7L, 7L, 7L ), .Label = c("i", "r", "s", "t", "x", "y", "z"), class = "factor"), value = structure(c(1L, 21L, 2L, 1L, 30L, 32L, 4L, 32L, 5L, 20L, 5L, 1L, 24L, 12L, 26L, 24L, 12L, 15L, 26L, 14L, 15L, 23L, 13L, 11L, 23L, 25L, 23L, 6L, 7L, 3L, 8L, 19L, 3L, 19L, 28L, 16L, 18L, 18L, 17L, 31L, 29L, 10L, 27L, 22L, 9L, 22L, 22L, 9L, 9L, 35L, 33L, 33L, 33L, 34L), .Label = c("0", "0,", "142,1", "1506,6", "1520,4", "170,36", "18,6185", "19,2933", "20,2125", "20,7423", "225,94", "23,2245", "24,3526", "24,3685", "24,4593", "242,84", "25,7422", "26,34", "26,5989", "30,6284", "36,6608", "39,913", "41,4933", "43,9104", "47,1241", "49,3467", "49,5715", "50,0037", "50,7974", "53,6667", "56,2778", "76", "76,5", "77,6667", "82"), class = "factor")), .Names = c("loc", "variables", "value"), class = "data.frame", row.names = c(NA, -54L)) Thanks Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] t-test across columns
Dear all, I would like to do t-test across two columns "name" with different "cat" with overall mean ("val"). (Removing if there is a single observation) And finally, make a matrix with t-value and p-value associated with a name (in rows) and cat (in columns) dput(x) structure(list(name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("12.2", "15.9" ), class = "factor"), cat = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 3L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("p178266580", "p178269196", "p178316310", "p191287337", "p195158904", "p196921846", "p197427158", "p238921966"), class = "factor"), val = c(148.90772, 184.253375, 183.97486667, 191.868125, 173.30515, 187.876975, 177.453775, 184.799525, 212.39065, 205.504525, 186.152025, 194.337075, 193.2703, 204.71665, 211.4452, 202.609175, 203.72918, 193.7261, 196.1186, 202.79556, 203.48818, 191.13744, 205.23315, 198.66842, 196.81032, 200.90512, 206.13564, 205.372225, 196.22835, 211.04686, 219.9771, 224.7602, 231.6596, 211.10581667, 215.44474, 210.83514, 228.173125, 224.09034, 212.96026, 239.0085, 213.5407, 227.12115, 209.24888, 232.8964, 232.22146, 228.1643, 236.43082, 232.20792, 238.49192, 224.64014, 233.75898, 207.06138, 215.3649, 211.14802, 201.86854, 200.52278, 199.05752, 194.90904, 214.44334, 249.35726667, 239.98525, 234.50848333, 243.86508333, 233.59581667, 248.1219, 225.28941667, 248.22088333, 193.69566, 198.43578, 205.06055, 208.525975, 198.28692, 206.88496, 201.60162, 205.7943, 210.5117, 196.69886, 193.58288, 198.86094, 201.81676, 225.8266, 205.879725, 218.370475, 214.006125, 198.74038, 206.00314, 198.37446, 225.5357, 216.721025, 226.543925, 158.1011, 158.15674, 166.07518, 179.942225, 158.16046, 165.0685, 159.56146 )), .Names = c("name", "cat", "val"), class = "data.frame", row.names = c( NA, 97L)) Thanks Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Transpose of the rows
Dear R users, I am using a big data matrix and need to transpose rows (formatting of input matrix). I would like write a general code for this example. for example: my input file is "dta" dput(dta) structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("TN00016-003A", "TN00016-014A", "TN00031-014A"), class = "factor"), name = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L), .Label = c("AreaCycl", "AreaEmer", "AreaMax", "HeightMax", "nrfilledseed"), class = "factor"), value = structure(c(3L, 7L, 8L, 14L, 12L, 1L, 2L, 9L, 5L, 13L, 11L, 10L, 4L, 6L), .Label = c("-0,584379415", "-0,842892819", "-1,399894415", "-1200,824457", "-13,59414667", "-25,86897333", "-3,277150907", "-3281,076515", "-7939,444248", "0,174160882", "0,800196212", "1,825", "12,2", "8,43449"), class = "factor")), .Names = c("id", "name", "value"), class = "data.frame", row.names = c(NA, -14L )) And output should look like this: dput(dta1) structure(list(id = structure(1:3, .Label = c("TN00016-003A", "TN00016-014A", "TN00031-014A"), class = "factor"), AreaCycl = structure(c( 2L, 1L, 3L), .Label = c("-0,584379415", "-1,399894415", "0,800196212" ), class = "factor"), AreaEmer = structure(c(2L, 1L, 3L), .Label = c( "-0,842892819", "-3,277150907", "0,174160882"), class = "factor"), AreaMax = structure(c( 2L, 3L, 1L), .Label = c("-1200,824457", "-3281,076515", "-7939,444248" ), class = "factor"), HeightMax = structure(c(3L, 1L, 2L), .Label = c( "-13,59414667", "-25,86897333", "8,43449"), class = "factor"), nrfilledseed = structure( c(1L, 2L, NA), .Label = c("1,825", "12,2"), class = "factor")), .Names = c("id", "AreaCycl", "AreaEmer", "AreaMax", "HeightMax", "nrfilledseed" ), class = "data.frame", row.names = c(NA, -3L)) Thanks for your help. Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fetch and merge from a data set
Many thanks Rui, However If I want to extract only first column (data1) from data file, then how Can I do it? Thanks again Nico On Tue, Jun 25, 2013 at 11:43 AM, Rui Barradas wrote: > Hello, > > I'm not sure I understand, but it seems as simple as > > merge(data1, data) > > > Hope this helps, > > Rui Barradas > > Em 25-06-2013 10:34, Nico Met escreveu: > >> Dear all, >> >> I would like to fetch a list (data1) of entities from a big data file >> (data) and merged together. for example: data is the file from where I >> want >> to extract >> >> dput(data) >> structure(list(NAME = structure(c(6L, 6L, 7L, 6L, 6L, 7L, 6L, >> 7L, 3L, 5L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, 1L, >> 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("CDS0008_3", >> "CDS0008_9", "CDS0248_2", "CDS0248_3", "CDS0248_9", "CDS0644", >> "CDS0645"), class = "factor"), QUAL = structure(c(1L, 1L, 1L, >> 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, >> 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("CE", >> "IE", "IL", "NL"), class = "factor"), DIFF = c(-1.3998944145561, >> -3.2771509067793, -3281.0765147, 8.434493332, 1.825, >> -0.584379415213178, -0.842892819141902, -7939.444248, >> 0.305343667019102, >> 11.4859716384148, 1242.7216649, 33.25400, -14.8, >> 62.8783807080717, 0.3234355, 3325.4720195, 33.8787927988058, >> -26.772370001, 58.6, 58.6, 0.0566947723248923, >> 1.294147, -13.319016665, -18.2, -76.008156572, -13.319016665, >> -18.2, -13.319016665, -18.2, -2632.77274125, -42.6985227297727, >> -19.2272727272727, -640.535327886362), PVALUE = c(0.393708851005828, >> 0.213217899579307, 0.59042649939326, 0.874157227673879, 0.953482720079014, >> 0.737143165148719, 0.76195136190783, 0.27992628190224, 0.737143165148719, >> 0.76195136190783, 0.27992628190224, 0.672772547835936, 0.86918514824479, >> 0.86918514824479, 0.794677241773376, 0.67568899695407, 0.0792182671307693, >> 0.53713122011077, 0.298506678908869, 0.343822055403655, 0.962553162399683, >> 0.335590623453015, 0.962553162399683, 0.335590623453015, >> 0.966426100547593, >> 0.671619043425778, 0.225088848812347, 0.962553162399683, >> 0.335590623453015, >> 0.17524845367103, 0.205476355179601, 0.229212899348569, 0.739457737437997 >> ), MEAD = c(61.997380489015, 38.9012158419308, 42541.899878, >> 644.34279333, 58.8, 65.4391126224113, 45.1617170900398, >> 37470.374736, >> 61.6954795437718, 36.4397768557611, 26367.622967, 485.3921, >> 76, 0, 0.8717201, 28005.1589441667, 46.2203164422305, >> 713.02971667, 64, 64, 23.0947770774977, 1.456775, 79.2102758175251, >> 39.5498022382743, 31387.15404, 883.47568, 180, 76.8751996288758, >> 41.0701371024372, 23960.47775025, 746.3317500025, 104.5, 17488.00655825 >> )), .Names = c("NAME", "QUAL", "DIFF", "PVALUE", "MEAD"), class = >> "data.frame", >> row.names = c(NA, >> 33L)) >> >> >> And data1 : subset of entities >> >> dput(data1) >> structure(list(NAME = structure(c(5L, 4L, 2L, 3L, 1L), .Label = >> c("CDG981", >> "CDS0248_2", "CDS0248_9", "CDS0644", "CDS0645"), class = "factor"), >> VAL = structure(c(1L, 2L, 5L, 3L, 4L), .Label = c("YU1", >> "YU2", "YU4", "YU5", "YU7"), class = "factor")), .Names = c("NAME", >> "VAL"), class = "data.frame", row.names = c(NA, 5L)) >> >> >> Please help me how can I do it. >> >> Many thanks >> >> Nico >> >> [[alternative HTML version deleted]] >> >> __** >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >> PLEASE do read the posting guide http://www.R-project.org/** >> posting-guide.html <http://www.R-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> >> [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fetch and merge from a data set
Dear all, I would like to fetch a list (data1) of entities from a big data file (data) and merged together. for example: data is the file from where I want to extract dput(data) structure(list(NAME = structure(c(6L, 6L, 7L, 6L, 6L, 7L, 6L, 7L, 3L, 5L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("CDS0008_3", "CDS0008_9", "CDS0248_2", "CDS0248_3", "CDS0248_9", "CDS0644", "CDS0645"), class = "factor"), QUAL = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("CE", "IE", "IL", "NL"), class = "factor"), DIFF = c(-1.3998944145561, -3.2771509067793, -3281.0765147, 8.434493332, 1.825, -0.584379415213178, -0.842892819141902, -7939.444248, 0.305343667019102, 11.4859716384148, 1242.7216649, 33.25400, -14.8, 62.8783807080717, 0.3234355, 3325.4720195, 33.8787927988058, -26.772370001, 58.6, 58.6, 0.0566947723248923, 1.294147, -13.319016665, -18.2, -76.008156572, -13.319016665, -18.2, -13.319016665, -18.2, -2632.77274125, -42.6985227297727, -19.2272727272727, -640.535327886362), PVALUE = c(0.393708851005828, 0.213217899579307, 0.59042649939326, 0.874157227673879, 0.953482720079014, 0.737143165148719, 0.76195136190783, 0.27992628190224, 0.737143165148719, 0.76195136190783, 0.27992628190224, 0.672772547835936, 0.86918514824479, 0.86918514824479, 0.794677241773376, 0.67568899695407, 0.0792182671307693, 0.53713122011077, 0.298506678908869, 0.343822055403655, 0.962553162399683, 0.335590623453015, 0.962553162399683, 0.335590623453015, 0.966426100547593, 0.671619043425778, 0.225088848812347, 0.962553162399683, 0.335590623453015, 0.17524845367103, 0.205476355179601, 0.229212899348569, 0.739457737437997 ), MEAD = c(61.997380489015, 38.9012158419308, 42541.899878, 644.34279333, 58.8, 65.4391126224113, 45.1617170900398, 37470.374736, 61.6954795437718, 36.4397768557611, 26367.622967, 485.3921, 76, 0, 0.8717201, 28005.1589441667, 46.2203164422305, 713.02971667, 64, 64, 23.0947770774977, 1.456775, 79.2102758175251, 39.5498022382743, 31387.15404, 883.47568, 180, 76.8751996288758, 41.0701371024372, 23960.47775025, 746.3317500025, 104.5, 17488.00655825 )), .Names = c("NAME", "QUAL", "DIFF", "PVALUE", "MEAD"), class = "data.frame", row.names = c(NA, 33L)) And data1 : subset of entities dput(data1) structure(list(NAME = structure(c(5L, 4L, 2L, 3L, 1L), .Label = c("CDG981", "CDS0248_2", "CDS0248_9", "CDS0644", "CDS0645"), class = "factor"), VAL = structure(c(1L, 2L, 5L, 3L, 4L), .Label = c("YU1", "YU2", "YU4", "YU5", "YU7"), class = "factor")), .Names = c("NAME", "VAL"), class = "data.frame", row.names = c(NA, 5L)) Please help me how can I do it. Many thanks Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] split and common variables
Dear Dr. David, Many thanks for your answer. Now, if I want to see if there are common "name"in those "places" , how can I do it? So, by common I mean, it might be compared with 2, 3, 4 all of them. All possible combinations Many thanks regards Nico On Mon, Jun 3, 2013 at 5:20 PM, David Carlson wrote: > It may be easier if you convert the list you provided to a > data.frame: > > > dta.df <- data.frame(place=dta$place, name=dta$name, > value=dta$value) > > dta.df > > Note that the last line is blank so you probably want to remove that > and remove the blank factor levels: > > > dta.df <- dta.df[-nrow(dta.df),] > > dta.df$place <- factor(dta.df$place) > > dta.df$name <- factor(dta.df$name) > > dta.df > > Now you can make a list containing separate data.frames by place > > > dta.df.sp <- split(dta.df, dta.df$place) > > dta.df.sp > > - > David L Carlson > Associate Professor of Anthropology > Texas A&M University > College Station, TX 77840-4352 > > > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Nico Met > Sent: Monday, June 3, 2013 8:42 AM > To: R help > Subject: [R] split and common variables > > Dear all, > > I would like to split the data based on the "place" and then would > like to > see how many "names" were common in place with corresponding "value" > . > > Please find a demo file. > > Thanks for your expert comment > > best > > Nico > > > dput(dta) > structure(list(place = structure(c(3L, 2L, 5L, 6L, 4L, 3L, 2L, > 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 3L, 2L, 5L, 6L, > 4L, 3L, 2L, 5L, 6L, 4L, 5L, 6L, 4L, 5L, 6L, 1L), .Label = c("", > "GCKT", "IKLI", "KLOI", "PLRT", "POIV"), class = "factor"), name = > structure > (c(2L, > 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 2L, 3L, 4L, 5L, 6L, > 7L, 8L, 9L, 10L, 11L, 12L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, > 11L, 12L, 12L, 1L), .Label = c("", "P_CK23", "P_CK24", "P_CK25", > "P_CK26", "P_CK27", "P_CK28", "P_CK29", "P_CK30", "P_CK31", > "P_CK32", > "P_CK33"), class = "factor"), value = c(5.9464, 6.0786, -4.5155, > 15.0241, -38.1847, -0.0861, 1.2757, -23.9914, 9.5951, -11.128, > 6.2826, 23.5218, 20.862, 3.1626, 6.242, -20.5348, -14.0126, -13.796, > 15.3869, -15.7409, -8.1963, -14.4522, 3.2117, -1.2738, 14.3556, > -12.5337, 20.4308, -3.3227, -34.802, -11.1103, -9.7146, -35.9044, > -9.4303, -28.1949, NA)), .Names = c("place", "name", "value"), class > = "data > .frame", row.names = c(NA, > 35L)) > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] split and common variables
Dear all, I would like to split the data based on the "place" and then would like to see how many "names" were common in place with corresponding "value" . Please find a demo file. Thanks for your expert comment best Nico > dput(dta) structure(list(place = structure(c(3L, 2L, 5L, 6L, 4L, 3L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 3L, 2L, 5L, 6L, 4L, 3L, 2L, 5L, 6L, 4L, 5L, 6L, 4L, 5L, 6L, 1L), .Label = c("", "GCKT", "IKLI", "KLOI", "PLRT", "POIV"), class = "factor"), name = structure (c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 12L, 1L), .Label = c("", "P_CK23", "P_CK24", "P_CK25", "P_CK26", "P_CK27", "P_CK28", "P_CK29", "P_CK30", "P_CK31", "P_CK32", "P_CK33"), class = "factor"), value = c(5.9464, 6.0786, -4.5155, 15.0241, -38.1847, -0.0861, 1.2757, -23.9914, 9.5951, -11.128, 6.2826, 23.5218, 20.862, 3.1626, 6.242, -20.5348, -14.0126, -13.796, 15.3869, -15.7409, -8.1963, -14.4522, 3.2117, -1.2738, 14.3556, -12.5337, 20.4308, -3.3227, -34.802, -11.1103, -9.7146, -35.9044, -9.4303, -28.1949, NA)), .Names = c("place", "name", "value"), class = "data .frame", row.names = c(NA, 35L)) > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Coversion from yearly to weekly data
Dear all, I have a big data matrix and I want to convert those data into weekly basis which means 7 days needs to be avaraged and aggregate a single value > dput(test) structure(list(locid = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "EC", class = "factor"), Day = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ), Data = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
[R] Correlation with p value
Dear all, I have a data (bellow) and I want to make a correlation test with p-value structure(list(Name = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("CTJ", "PKR", "TTK"), class = "factor"), score = c(86.4371428571428, 89.7028571428572, 87.728, 89.99, 89.42, 85.6914285714286, 82.256, 83.9942857142857, 86.4371428571429, 84.596, 84.74, 87.8771428571428, 83.12, 81.824, 88.5457142857143, 85.7171428571429, 84.902, 89.8828571428571, 91.5542857142857, 89.42, 86.81)), .Names = c("Name", "score"), class = "data.frame", row.names = c(NA, 21L)) And finally , I would like to display as matrix where I can fill up with p-values *TTK* *CTJ* *PKR* *TTK* ** ** ** *CTJ* ** ** ** *PKR* Many thanks for your help in advance Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Average calculations
Dear all, I have a matrix with two columns: "Names" and "Values" In names: there are 4 groups they are, CK113234, CK116296, CK116292 and CK114042 I want to *sort values* (decreasing order) based on each group and take average of the *top two numbers* in each of the groups. > dput(x) structure(list(Names = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("CK113234", "CK113298", "CK114042", "CK116292", "CK116296"), class = "factor"), Values = c(208.3360, 223.29665, 221.63255, 211.29735, 217.75112, 210.97916, 222.67365, 216.0822, 189.83685, 194.1595, 210.66298, 223.63718333, 187.74864, 192.5964, 237.593625, 216.8277, 225.8966, 228.00374, 214.99454, 211.38114, 218.7659, 209.9958, 214.8041, 215.184489473684, 224.2446, 217.559878571429, 232.02229167, 214.02384, 236.393875, 228.73522)), .Names = c("Names", "Values"), class = "data.frame", row.names = c(NA, 30L)) The out put will look like following: Names Values CK113234 222,98 CK116296 217,14 CK116292 232,79 CK114042 234,2 Your help is appreciated. Regards Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xlsx file read in R
Dear all, this is the code I used to read the .xlsx file but get an error message library(rJava) library(XLConnectJars) library(XLConnect) file<-readWorksheetFromFile("all_in.xlsx", sheet = 1) *Error: NoClassDefFoundError (Java): Could not initialize class org.apache.poi.POIXMLDocument* No idea where it went wrong Regards Nico On Mon, Dec 3, 2012 at 2:07 PM, jim holtman wrote: > use the XLConnect package. > > On Mon, Dec 3, 2012 at 7:59 AM, Nico Met wrote: > > Dear all, > > > > How can I read .xlsx files in R > > > > Regards Nico > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > -- > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > Tell me what you want to do, not how you want to do it. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] xlsx file read in R
Dear all, How can I read .xlsx files in R Regards Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mean value calculation
Dear all, I want to calculate mean values for multiple rows: structure(list(Name = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("AKT", "CKT"), class = "factor"), val1 = c(2, 3, 2, 2, 2, 5, 3, 8, 2), val2. = c(4, 5, 4, 8, 4, 8, 4, 7, 4), val3 = c(5, 6, 5, 9, 5, 9, 5, 9, 5)), .Names = c("Name", "val1", "val2.", "val3"), class = "data.frame", row.names = c(NA, 9L)) For example: as an output I must get Name val1 val2 val3 AKT CKT I wrote this : #as.matrix(tapply(dat[,2:4], dat[,1], FUN = mean)) Error in as.matrix(tapply(met[, 2:4], met[, 1], FUN = mean)) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error in tapply(met[, 2:4], met[, 1], FUN = mean) : arguments must have same length Thanks for you kind advise Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to count combinations
Dear all, Need a help. I would like to count combination of two columns: structure(list(V1 = structure(c(4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("23", "55", "67", "Env"), class = "factor"), V2 = structure(c(9L, 7L, 7L, 7L, 2L, 1L, 11L, 11L, 11L, 11L, 5L, 6L, 6L, 3L, 8L, 2L, 1L, 4L, 4L, 10L, 10L, 10L), .Label = c("Ck", "CK", "Dk", "IN", "jk", "NO", "NW", "PK", "place", "PR", "PT"), class = "factor")), .Names = c("V1", "V2"), class = "data.frame", row.names = c(NA, 22L)) For example: how many times 23 appear with NW and then I want to put the out put as a matrix NW Ck PT jK NO DK PK IN PR 23 3 55 67 Many thanks in advance Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] t-test
Many many thanks for the input in this context. Nico On Thu, Oct 4, 2012 at 4:56 PM, Jose Iparraguirre < jose.iparragui...@ageuk.org.uk> wrote: > Hi, > > You can also have a look at this paper (no subscription needed): > > Herberich, E.; Sikorski, J.; and Hothorn, T. (2010). "A Robust Procedure > for Comparing Multiple Means under Heteroscedasticity in Unbalanced > Designs". PLoSONE, Vol. 5, Issue 3, e9788. doi:10.1371/journal.pone.0009788 > > In this paper, Herberich et al have included a piece of R code to run > their procedure. Their procedure is a modification of Tukey, and as it says > in the title of the paper, it can be used regardless of whether the samples > had different sizes or distributions. > > José > > > José Iparraguirre > Chief Economist > Age UK > > T 020 303 31482 > E jose.iparragui...@ageuk.org.uk > Twitter @jose.iparraguirre@ageuk > > > Tavis House, 1- 6 Tavistock Square > London, WC1H 9NB > www.ageuk.org.uk | ageukblog.org.uk | @ageukcampaigns > > > For a copy of our new Economic Monitor and the full Chief Economist's > report, visit the Age UK Knowledge Hub > http://www.ageuk.org.uk/professional-resources-home/knowledge-hub-evidence-statistics/ > > > For evidence and statistics on the older population, visit the Age UK > Knowledge Hub > http://www.ageuk.org.uk/professional-resources-home/knowledge-hub-evidence-statistics/ > > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of arun > Sent: 04 October 2012 13:59 > To: John Kane > Cc: R help > Subject: Re: [R] t-test > > Hi John, > You are right. With more than two groups, the type 1 error rate should be > a problem. > A.K. > > > > - Original Message - > From: John Kane > To: arun > Cc: > Sent: Thursday, October 4, 2012 8:40 AM > Subject: Re: [R] t-test > > My stats are lousy but isnt Nico doing some multiple t-tests when an anova > with some post hoc comparisons complete with a Tukey or Bonferroni > correction looks more suitable? > > Of course I have no idea of the topic area and maybe he has already done > thi. > > John Kane > Kingston ON Canada > > > > -Original Message- > > From: smartpink...@yahoo.com > > Sent: Thu, 4 Oct 2012 05:31:55 -0700 (PDT) > > To: nicome...@gmail.com > > Subject: Re: [R] t-test > > > > HI, > > Try this: > > sapply(split(dat,dat$Name),function(x) t.test(x[,2],dat[,2])$p.value) > > #CTK100 CTK103 CTK121 > > #0.86330310 0.32706859 0.02023357 > > A.K. > > > > > > > > - Original Message - > > From: Nico Met > > To: Rui Barradas > > Cc: r-help@r-project.org; r-help > > Sent: Thursday, October 4, 2012 6:37 AM > > Subject: Re: [R] t-test > > > > Dear Rui, > > > > Many thanks for help. > > > > "mean for CTK and all" = comparison between mean of all groups ( which > > means second col) vs. each groups like CTK100, CTK121 etc. > > > > Regards > > > > Nico > > > > On Thu, Oct 4, 2012 at 12:28 PM, Rui Barradas > > wrote: > > > >> Hello, > >> > >> I'm not quite sure I understand, but something like this? > >> > >> tapply(dat$Score, dat$Name, FUN = mean) > >> sapply(unique(dat$Name), function(un){ > > > with(dat, t.test(Score[Name == un], Score[Name != un])$p.value)}) > >> > >> My doubt is in what you mean by "mean for CTK and all". The ?t.test > >> gives > >> a confidence interval for the difference in the means, so maybe you'll > >> have > >> to look there for what you want. > >> > >> Hope this helps, > >> > >> Rui Barradas > >> Em 04-10-2012 10:34, Nico Met escreveu: > >> > >>> Dear Group, > >>> > >>> I want to do a t-test calculation on a large data set. > >>> > >>> I am pasting some part of it > >>> > >>> structure(list(Name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 3L, > >>> 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > >>> 2L), .Label = c("CTK100", "CTK103", "CTK121"), class = "factor"), > > >> Score = c(236.9726, 207.0055, 237.3464, 224.4774, 236.5034, > > >> 206.7382, 233.94, 240.31, 240.9, 235.15, 223.36, 248.67, > > >> 249.25, 201.4051, 244.1689, 182.2756, 229.001, 241.3211, > > >> 196.0453, 232.6055, 225.0783, 196.045
Re: [R] t-test
Dear Rui, Many thanks for help. "mean for CTK and all" = comparison between mean of all groups ( which means second col) vs. each groups like CTK100, CTK121 etc. Regards Nico On Thu, Oct 4, 2012 at 12:28 PM, Rui Barradas wrote: > Hello, > > I'm not quite sure I understand, but something like this? > > tapply(dat$Score, dat$Name, FUN = mean) > sapply(unique(dat$Name), function(un){ > with(dat, t.test(Score[Name == un], Score[Name != un])$p.value)}) > > My doubt is in what you mean by "mean for CTK and all". The ?t.test gives > a confidence interval for the difference in the means, so maybe you'll have > to look there for what you want. > > Hope this helps, > > Rui Barradas > Em 04-10-2012 10:34, Nico Met escreveu: > >> Dear Group, >> >> I want to do a t-test calculation on a large data set. >> >> I am pasting some part of it >> >> structure(list(Name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 3L, >> 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, >> 2L), .Label = c("CTK100", "CTK103", "CTK121"), class = "factor"), >> Score = c(236.9726, 207.0055, 237.3464, 224.4774, 236.5034, >> 206.7382, 233.94, 240.31, 240.9, 235.15, 223.36, 248.67, >> 249.25, 201.4051, 244.1689, 182.2756, 229.001, 241.3211, >> 196.0453, 232.6055, 225.0783, 196.0453, 232.6055, 225.0783 >> )), .Names = c("Name", "Score"), class = "data.frame", row.names = >> c(NA, >> 24L)) >> >> >> I want to compare groups with CTK100 and with all the groups and want to >> save the p-values and mean for each of that particular group (for example: >> mean for CTK and all) >> Similarly, for other groups like that CTK121 etc... >> >> Is there any way to automate this process? >> >> Thanks for your advice ! >> >> Nico >> >> [[alternative HTML version deleted]] >> >> __** >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >> PLEASE do read the posting guide http://www.R-project.org/** >> posting-guide.html <http://www.R-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] t-test
Dear Group, I want to do a t-test calculation on a large data set. I am pasting some part of it structure(list(Name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("CTK100", "CTK103", "CTK121"), class = "factor"), Score = c(236.9726, 207.0055, 237.3464, 224.4774, 236.5034, 206.7382, 233.94, 240.31, 240.9, 235.15, 223.36, 248.67, 249.25, 201.4051, 244.1689, 182.2756, 229.001, 241.3211, 196.0453, 232.6055, 225.0783, 196.0453, 232.6055, 225.0783 )), .Names = c("Name", "Score"), class = "data.frame", row.names = c(NA, 24L)) I want to compare groups with CTK100 and with all the groups and want to save the p-values and mean for each of that particular group (for example: mean for CTK and all) Similarly, for other groups like that CTK121 etc... Is there any way to automate this process? Thanks for your advice ! Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting of columns of a matrix
Yes, each column shall have different sequence of row names N On Wed, Aug 29, 2012 at 5:21 PM, PIKAL Petr wrote: > Hi > > ** ** > > But in your example there are no row names? How would you structure the > result? Each column has different order and therefore each column shall > have different sequence of row names? > > ** ** > > Send also your responses to r-help as somebody could have better answer > for you. > > ** ** > > Regards > > Petr**** > > ** ** > > ** ** > > ** ** > > *From:* Nico Met [mailto:nicome...@gmail.com] > *Sent:* Wednesday, August 29, 2012 4:56 PM > *To:* PIKAL Petr > > *Subject:* Re: [R] Sorting of columns of a matrix > > ** ** > > Thanks a lot. > > ** ** > > But I also want to attach row names (if available) associated with each > column. > > ** ** > > In that case does your second code works in the same way? > > ** ** > > thanks > > ** ** > > Animesh > > ** ** > > ** ** > > On Wed, Aug 29, 2012 at 4:46 PM, PIKAL Petr > wrote: > > Hi > > > > > > -Original Message- > > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > > project.org] On Behalf Of Nico Met > > Sent: Wednesday, August 29, 2012 4:25 PM > > To: Berend Hasselman > > Cc: r-help@r-project.org > > Subject: Re: [R] Sorting of columns of a matrix > > > > Please find the require info: > > > > > > set.seed(12345) > > X<-matrix(rnorm(5*10),nrow=5) > > > > > > > > > > X[2,5]<-0 > > X[3,1]<-0 > > X[5,8]<-0 > > > > > > > dput(X) > > > > structure(c(0.585528817843856, 0.709466017509524, 0, - > > 0.453497173462763, 0.605887455840393, -1.81795596770373, > > > 0.630098551068391, -0.276184105225216, -0.284159743943371, - > > 0.919322002474128, -0.116247806352002, 1.81731204370422, > > 0.370627864257954, 0.520216457554957, -0.750531994502331, > > 0.816899839520583, -0.886357521243213, -0.331577589942552, > > 1.12071265166956, 0.298723699267293, 0.779621924555324, 0, - > > 0.644328429231302, -1.55313740522969, -1.59770951669631, > > 1.80509751881082, -0.481647363694637, 0.620379801298422, > > 0.612123492650849, -0.162310976918126, 0.81187317855386, > > 2.19683354634753, 2.04919033740619, 1.63244563948047, > > 0.254271192814055, 0.491188279272559, -0.324086578737118, - > > 1.66205024385863, 1.76773385087297, 0, 1.12851083359018, - > > 2.38035806139704, -1.06026555215253, 0.937140540182908, > > 0.854451720330554, 1.46072940310409, -1.4130987778892, > > 0.567403253424482, 0.583187653435685, -1.30679883346442), .Dim = c(5L, > > 10L)) > > > > I am not sure what do you want to do with it? Remove rows which has 0 > > X[X==0]<-NA > X[complete.cases(X),] > > remove zeroes and sort values independently in each column? > > X[X==0]<-NA > apply(X, 2, sort, decreasing=TRUE) > > results in list as you have various number of values in columns. > > Regards > Petr > > > > > > On Wed, Aug 29, 2012 at 4:16 PM, Berend Hasselman > > wrote: > > > > > > > > On 29-08-2012, at 16:08, Nico Met wrote: > > > > > > > Hello john, > > > > > > > > thanks for the suggestion. Please find an example: > > > > > > > >> X<-matrix(rnorm(5*10),nrow=5) > > > > > > > >> dim(X) > > > > [1] 5 10 > > > >> X > > > > [,1] [,2][,3] [,4] [,5] > > [,6] > > > > [,7] [,8] [,9] [,10] > > > > [1,] 1.2774431 -1.2427735 0.81933548 -2.1098586 -1.6726799 > > > > -2.2994684 > > > > -0.28823228 0.1929301 0.1187168 -1.2078372 [2,] 0.5969187 > > > > -1.2571336 0.30292368 -0.2098139 -0.9689961 1.7105109 > > > > 0.77240398 0.1482712 -1.2486152 0.2359723 [3,] -0.9669289 > > > > -0.2315229 1.04611417 0.7902772 0.5791674 0.6296305 > > > > -0.60517647 0.5317435 -0.2556417 -0.4838956 [4,] -1.9345400 > > > > 0.2898647 0.08983352 0.1482130 0.8229054 0.7778114 > > > > 0.49423641 0.4015327 2.8596603 0.6618432 [5,] -1.1969226 > > > > -1.3991657 -0.76507258 0.5024922 0.2633307 0.0236774 > > > > -0.09497448 -0.3986624 0.1327156 -0.8935923 > > > > > > > >> X[2,5]<-0 > > > >> X[3,1]<-0 > > > >> X[6,8]<-0 > &
Re: [R] Sorting of columns of a matrix
Please find the require info: set.seed(12345) X<-matrix(rnorm(5*10),nrow=5) dim(X) X [,1] [,2][,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.2774431 -1.2427735 0.81933548 -2.1098586 -1.6726799 -2.2994684 -0.28823228 0.1929301 0.1187168 -1.2078372 [2,] 0.5969187 -1.2571336 0.30292368 -0.2098139 -0.9689961 1.7105109 0.77240398 0.1482712 -1.2486152 0.2359723 [3,] -0.9669289 -0.2315229 1.04611417 0.7902772 0.5791674 0.6296305 -0.60517647 0.5317435 -0.2556417 -0.4838956 [4,] -1.9345400 0.2898647 0.08983352 0.1482130 0.8229054 0.7778114 0.49423641 0.4015327 2.8596603 0.6618432 [5,] -1.1969226 -1.3991657 -0.76507258 0.5024922 0.2633307 0.0236774 -0.09497448 -0.3986624 0.1327156 -0.8935923 X[2,5]<-0 X[3,1]<-0 X[5,8]<-0 X [,1] [,2][,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.2774431 -1.2427735 0.81933548 -2.1098586 -1.6726799 -2.2994684 -0.28823228 0.1929301 0.1187168 -1.2078372 [2,] 0.5969187 -1.2571336 0.30292368 -0.2098139 0.000 1.7105109 0.77240398 0.1482712 -1.2486152 0.2359723 [3,] 0.000 -0.2315229 1.04611417 0.7902772 0.5791674 0.6296305 -0.60517647 0.5317435 -0.2556417 -0.4838956 [4,] -1.9345400 0.2898647 0.08983352 0.1482130 0.8229054 0.7778114 0.49423641 0.4015327 2.8596603 0.6618432 [5,] -1.1969226 -1.3991657 -0.76507258 0.5024922 0.2633307 0.0236774 -0.09497448 0.000 0.1327156 -0.8935923 dput(X) structure(c(0.585528817843856, 0.709466017509524, 0, -0.453497173462763, 0.605887455840393, -1.81795596770373, 0.630098551068391, -0.276184105225216, -0.284159743943371, -0.919322002474128, -0.116247806352002, 1.81731204370422, 0.370627864257954, 0.520216457554957, -0.750531994502331, 0.816899839520583, -0.886357521243213, -0.331577589942552, 1.12071265166956, 0.298723699267293, 0.779621924555324, 0, -0.644328429231302, -1.55313740522969, -1.59770951669631, 1.80509751881082, -0.481647363694637, 0.620379801298422, 0.612123492650849, -0.162310976918126, 0.81187317855386, 2.19683354634753, 2.04919033740619, 1.63244563948047, 0.254271192814055, 0.491188279272559, -0.324086578737118, -1.66205024385863, 1.76773385087297, 0, 1.12851083359018, -2.38035806139704, -1.06026555215253, 0.937140540182908, 0.854451720330554, 1.46072940310409, -1.4130987778892, 0.567403253424482, 0.583187653435685, -1.30679883346442), .Dim = c(5L, 10L)) On Wed, Aug 29, 2012 at 4:16 PM, Berend Hasselman wrote: > > On 29-08-2012, at 16:08, Nico Met wrote: > > > Hello john, > > > > thanks for the suggestion. Please find an example: > > > >> X<-matrix(rnorm(5*10),nrow=5) > > > >> dim(X) > > [1] 5 10 > >> X > > [,1] [,2][,3] [,4] [,5] [,6] > > [,7] [,8] [,9] [,10] > > [1,] 1.2774431 -1.2427735 0.81933548 -2.1098586 -1.6726799 -2.2994684 > > -0.28823228 0.1929301 0.1187168 -1.2078372 > > [2,] 0.5969187 -1.2571336 0.30292368 -0.2098139 -0.9689961 1.7105109 > > 0.77240398 0.1482712 -1.2486152 0.2359723 > > [3,] -0.9669289 -0.2315229 1.04611417 0.7902772 0.5791674 0.6296305 > > -0.60517647 0.5317435 -0.2556417 -0.4838956 > > [4,] -1.9345400 0.2898647 0.08983352 0.1482130 0.8229054 0.7778114 > > 0.49423641 0.4015327 2.8596603 0.6618432 > > [5,] -1.1969226 -1.3991657 -0.76507258 0.5024922 0.2633307 0.0236774 > > -0.09497448 -0.3986624 0.1327156 -0.8935923 > > > >> X[2,5]<-0 > >> X[3,1]<-0 > >> X[6,8]<-0 > >> X[5,8]<-0 > >> X > > [,1] [,2][,3] [,4] [,5] [,6] > > [,7] [,8] [,9] [,10] > > [1,] 1.2774431 -1.2427735 0.81933548 -2.1098586 -1.6726799 -2.2994684 > > -0.28823228 0.1929301 0.1187168 -1.2078372 > > [2,] 0.5969187 -1.2571336 0.30292368 -0.2098139 0.000 1.7105109 > > 0.77240398 0.1482712 -1.2486152 0.2359723 > > [3,] 0.000 -0.2315229 1.04611417 0.7902772 0.5791674 0.6296305 > > -0.60517647 0.5317435 -0.2556417 -0.4838956 > > [4,] -1.9345400 0.2898647 0.08983352 0.1482130 0.8229054 0.7778114 > > 0.49423641 0.4015327 2.8596603 0.6618432 > > [5,] -1.1969226 -1.3991657 -0.76507258 0.5024922 0.2633307 0.0236774 > > -0.09497448 0.000 0.1327156 -0.8935923 > > This is just as unreadable as your first try. > Please do as suggested > > dput(X) > > and also include a set.seed() before generating the matrix to make it > reproducible. > > Berend > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting of columns of a matrix
Hello john, thanks for the suggestion. Please find an example: > X<-matrix(rnorm(5*10),nrow=5) > dim(X) [1] 5 10 > X [,1] [,2][,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.2774431 -1.2427735 0.81933548 -2.1098586 -1.6726799 -2.2994684 -0.28823228 0.1929301 0.1187168 -1.2078372 [2,] 0.5969187 -1.2571336 0.30292368 -0.2098139 -0.9689961 1.7105109 0.77240398 0.1482712 -1.2486152 0.2359723 [3,] -0.9669289 -0.2315229 1.04611417 0.7902772 0.5791674 0.6296305 -0.60517647 0.5317435 -0.2556417 -0.4838956 [4,] -1.9345400 0.2898647 0.08983352 0.1482130 0.8229054 0.7778114 0.49423641 0.4015327 2.8596603 0.6618432 [5,] -1.1969226 -1.3991657 -0.76507258 0.5024922 0.2633307 0.0236774 -0.09497448 -0.3986624 0.1327156 -0.8935923 > X[2,5]<-0 > X[3,1]<-0 > X[6,8]<-0 > X[5,8]<-0 > X [,1] [,2][,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.2774431 -1.2427735 0.81933548 -2.1098586 -1.6726799 -2.2994684 -0.28823228 0.1929301 0.1187168 -1.2078372 [2,] 0.5969187 -1.2571336 0.30292368 -0.2098139 0.000 1.7105109 0.77240398 0.1482712 -1.2486152 0.2359723 [3,] 0.000 -0.2315229 1.04611417 0.7902772 0.5791674 0.6296305 -0.60517647 0.5317435 -0.2556417 -0.4838956 [4,] -1.9345400 0.2898647 0.08983352 0.1482130 0.8229054 0.7778114 0.49423641 0.4015327 2.8596603 0.6618432 [5,] -1.1969226 -1.3991657 -0.76507258 0.5024922 0.2633307 0.0236774 -0.09497448 0.000 0.1327156 -0.8935923 Now I want to sort and remove "zero" based on rows. for example for column 1: [1,]1.2774431 [2,]0.5969187 [5,]-1.1969226 [4,]-1.9345400 Regards Nico On Wed, Aug 29, 2012 at 3:29 PM, John Kane wrote: > Perhaps you could supply the matrix using dput() ? It is a handy way to > supply sample data. Just do dput(mydata), copy the results and paste into > email. > > At the moment your matrix is almost unreadable. > > John Kane > Kingston ON Canada > > > > -Original Message- > > From: nicome...@gmail.com > > Sent: Wed, 29 Aug 2012 15:24:17 +0200 > > To: r-help@r-project.org > > Subject: [R] Sorting of columns of a matrix > > > > Dear all, > > > > Please suggest me how can I do it. > > > > > > I have a matrix which look like following: > > > > x1 x2 x3 t1 .01 0.3 0 t2 0 0.1 0.01 t3 0 .01 .01 t4 0 0 t5 5 0 0 > > t6 > > 0 0 0 t7 0 0 0 t8 0 0 0 t9 0.6 0 0 t10 0 0 0.66 t11 0 0.6 0.11 t12 > > 0 > > 0.4 0 > > > > I want to sort decreasing order in each column based on rows. and then to > > display only those rows which has a value. The expected out put matrix > > will > > look like > > > > x1 x2 x3 t9 0.6 t11 0.6 t10 0.66 t1 .01 t12 0.4 t11 0.11 t1 0.3 t2 > > .01 > > t2 0.1t3 .01 > > many thanks > > > > Nico > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > FREE ONLINE PHOTOSHARING - Share your photos online with your friends and > family! > Visit http://www.inbox.com/photosharing to find out more! > > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Sorting of columns of a matrix
Dear all, Please suggest me how can I do it. I have a matrix which look like following: x1 x2 x3 t1 .01 0.3 0 t2 0 0.1 0.01 t3 0 .01 .01 t4 0 0 t5 5 0 0 t6 0 0 0 t7 0 0 0 t8 0 0 0 t9 0.6 0 0 t10 0 0 0.66 t11 0 0.6 0.11 t12 0 0.4 0 I want to sort decreasing order in each column based on rows. and then to display only those rows which has a value. The expected out put matrix will look like x1 x2 x3 t9 0.6 t11 0.6 t10 0.66 t1 .01 t12 0.4 t11 0.11 t1 0.3 t2 .01 t2 0.1t3 .01 many thanks Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] elasticnet iteration problem
Dear all, I am trying to iterate an elastic net regression method on a matrix 1) Each column of the matrix ( nxp) will act as a response (y) and rest of the variables (columns) which means p-1 will act as predictor set 2) i want to store selected variables as matrix I wrote a code. Please help me to automate this procedure # install packages for analysis rm(list = ls()) library(caret) library(glmnet) X<-matrix(rnorm(100*500),nrow=100) y<-X[,1] # I want automatically it will take next column as a response means untill 500 columns X1<-X[,-1] # If I use first column as a response it should delete first column from the matrix dim(X1) ### Applicarion of the Elastic net for selecting the genes con<-trainControl(method="cv",number=10) fit_data<-train(X1, y,method="glmnet",metric="RMSE",trControl=con,tuneLength = 10) glmnetcalc<-glmnet(X1,y,alpha=fit_data$finalModel$tuneValue$.alpha) fitcoef<-predict(glmnetcalc,s=fit_data$finalModel$tuneValue$.alpha,type="coefficients") CoefEN_1<-as.matrix(fitcoef) write.table(CoefEN_1, "varSelect_1.txt") # I want to store the non zero values in a matrix thanks Nico [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.