similar to: Why can't this function be used with the 'by' command?

Displaying 20 results from an estimated 7000 matches similar to: "Why can't this function be used with the 'by' command?"

2011 Dec 08
1
How to plot multiple graphs in one go?
I am trying to do this, but it won't work: > library(lattice) > elemconc = data.frame(expand.grid(id=1:20, geno=c('exp', 'wt'), region=c('cor', 'cr', 'spine'), elem=c('fe', 'cu', 'zn')), conc=rnorm(360, 10)) > elemconc$geno = factor(elemconc$geno) > elemconc$region = factor(elemconc$region) > for (i in
2013 Apr 18
1
parSapply can't find function
Here is the code, assuming 8 cores in the cpu. library('modeest') library('snow') cl = makeCluster(rep('localhost', 8), 'SOCK') x = vector(length=50) x = sapply(x, function(i) i=sample(c(1,0), 1)) pastK = function(n, x, k) { if (n>k) { return(x[(n-k):(n-1)]) } else {return(NA)} } predR = function(x, k) { pastList = lapply(1:length(x), function(n)
2013 Apr 18
1
snow: cluster initialization
Dear all, I found a strange thing with the snow package. This will work: y = matrix(1:4, 2) cl = makeCluster(rep('localhost', 8), type='SOCK') parMM(cl, y, y) This will not: y = matrix(1:4, 2) ncore = system('nproc') parMM(cl, y, y) Error in cut.default(i, breaks) : invalid number of intervals I also tried: cl = makeCluster(rep('localhost', ncore),
2011 Dec 04
1
Complex multiple t tests in a data frame with several id factors
I have assayed the concentrations of various metal elements in different anatomic regions of two strains of mice. Now, for each element, in each region, I want to do a t test to find whether there is any difference between the two strains. Here is what I did (using simulated data as an example): # create the data frame > elemconc = data.frame(expand.grid(id=1:3, geno=c('exp',
2011 Dec 23
2
cast in reshape and reshape2
> library(reshape2) > x = melt(airquality, id=c('month', 'day')) With reshape I can cast with multiple functions: > library(reshape) > cast(x, month+variable~., c(mean,sd)) month variable mean sd 1 5 ozone 23.615385 22.224449 2 5 solar.r 181.296296 115.075499 3 5 wind 11.622581 3.531450 4 5 temp 65.548387
2011 Nov 23
2
Is there an easier way to iterate over multiple data frames in R?
> for (d in paste('df', 1:3, sep='')) { + assign(d, as.data.frame(replicate(3, rnorm(4)))) + } > dats = list(df1,df2,df3) > for (i in 1:length(dats)) { + names(dats[[i]]) = c('w', 'l', 'h') + } > dats [[1]] w l h 1 1.24319239 -0.05543649 0.05409178 2 0.05124331 -1.89346950 0.33896273 3 -1.69686777 -0.35963008
2014 Nov 10
1
Cursor not behaving properly
I found a strange bug in R recently (version 3.1.2): As you can see from the screenshots attached, when the cursor passes the right edge of the console, instead of start on a new line, it goes back to the beginning of the same line, and overwrites everything after it. This happens every time the size of the terminal is changed, for example, if you fit the terminal to the right half of the
2011 Nov 05
1
Correlation between matrices
> regions = c('cortex', 'hippocampus', 'brain_stem', 'mid_brain', 'cerebellum') > mice = paste('mouse', 1:5, sep='') > for (n in c('Cu', 'Fe', 'Zn', 'Ca', 'Enzyme')) { + assign(n, as.data.frame(replicate(5, rnorm(5)))) + } > names(Cu) = names(Zn) = names(Fe) = names(Ca) = names(Enzyme) =
2020 Oct 18
1
Resultado de la consola como un tibble
Hola, Bueno, puedes hacer el cálculo de una forma mucho más compacta y rápida. Esta forma es especialmente recomendable cuando tienes muchas columnas y muchas filas. > library(data.table) > myDT <- as.data.table(mtcars) > myDTlong <- melt(myDT, measure.vars=1:ncol(myDT)) > myDTlong[ , list(p_value = shapiro.test(value)$p.value, v_stat = shapiro.test(value)$statistic) , by
2013 Aug 25
0
"block incomplete" error when compiling R
Dear list, I am trying to compile R on a 64-bit Ubuntu 13.04 machine and get the following error: make[2]: Entering directory `/home/kaiyin/opt/R-2.15.0/src/library/Recommended' begin installing recommended package MASS Error in untar2(tarfile, files, list, exdir) : incomplete block on file make[2]: *** [MASS.ts] Error 1 make[2]: Leaving directory
2020 Oct 18
2
Resultado de la consola como un tibble
Buen día estimados Estoy tratando de hacer un tibble con los resultados de un apply que se muestran en la consola que me da R, no estoy seguro si eso se pueda hacer, pero me gustaría organizar los resultados de esa manera. mi código es: data("mtcars") Mtcars_matriz <- as.matrix(mtcars) apply(Mtcars_matriz, MARGIN =2, FUN = shapiro.test) DF2 <- tibble(Variable = NA, W = NA, Pvalue =
2011 Nov 24
1
what is wrong with this dataset?
> d = data.frame(gender=rep(c('f','m'), 5), pos=rep(c('worker', 'manager', 'speaker', 'sales', 'investor'), 2), lot1=rnorm(10), lot2=rnorm(10)) > d gender pos lot1 lot2 1 f worker 1.1035316 0.8710510 2 m manager -0.4824027 -0.2595865 3 f speaker 0.8933589 -0.5966119 4 m sales
2012 Apr 04
1
Shapiro-Wilk cpoefficients: 2 Qs
Greetings! I want to have the coefficients that R uses in shapiro.test() for the Shapiro-Wilk test for a prticular sample size, i.e. the a[i] in W = Sum(a[i]*x[i])/(Sum(x[i] - mean(x))^2) (where the x[i] are sorted). Two questions: Q1: Is there a readymade R function from which I can extract these? Q2: I was wondering if I might be able to modify the code for the function shapiro.test() so
2006 Jul 12
2
shapiro.test() output
R Users: My question is probably more about elementary statistics than the mechanics of using R, but I've been dabbling in R (version 2.2.0) and used it recently to test some data . I have a relatively small set of observations (n = 12) of arsenic concentrations in background groundwater and wanted to test my assumption of normality. I used the Shapiro-Wilk test (by calling shapiro.test()
2012 May 02
2
output Shapiro-Wild results to a table
Hello, I have applied the Shapiro test to a matrix with 26.925 rows of data using the following F1.norm<-apply(F1.n.mat,1,shapiro.test) I would now like to view and export a table of the p and W values from the Shapiro test, but I am not sure how to approach this. I have tried the following with errors. > write.table(x=F1.norm,file="I:/R_Work/F1/Shapiro.csv",
2000 Oct 07
2
Possible bug in apply()
In the course of applying Shapiro-Wilk to 100,000 samples of 60 items from 100,000 different distributions, I encountered a fatal error in apply(). This can be reconstructed as follows, using the attached data file distr.dat containing 2 lines of my original 100,000-line file: > version _ platform Windows arch x86 os Win32 system x86, Win32 status
2007 Jun 29
1
Shapiro Test P Value Incorrect? (PR#9768)
Full_Name: Jason Polak Version: R version 2.5.0 (2007-04-23) OS: Xubuntu 7.04 Submission from: (NULL) (137.122.144.35) Dear R group, I have noticed a strange anomaly with the shapiro.test() function. Unfortunately I do not know how to calculate the shapiro test P values manually so I don't know if this is an actual bug. So, to produce the results, run the following code: pvalues = 0; for
2005 Nov 09
1
Problems with Shapiro Wilk's test of normality.
Hi, I am trying to create a table with information from Shapiro Wilk's test of normality. However, it fails due to lack of sample size, it says, but the way I see it, this is not a problem. (See the table of sample sizes (almost) at the bottom). Applying a different function using a similar ftable call is not a problem (See the bottom table). This is R 2.1.0 on Linux (Gentoo). /Fredrik
2001 Jul 02
2
Shapiro-Wilk test
Hi, does the shapiro wilk test in R-1.3.0 work correctly? Maybe it does, but can anybody tell me why the following sample doesn't give "W = 1" and "p-value = 1": R> x<-1:9/10;x [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 R> shapiro.test(qnorm(x)) Shapiro-Wilk normality test data: qnorm(x) W = 0.9925, p-value = 0.9986 I can't imagine a sample being
2010 Sep 22
2
kstest vs shapirotest
Dear R-users Idea: Analysing tree height frequency with hist(), normal distribution (ks.test & shapiro.test) and skewness (package e1071 - thanks a lot for this useful package)as an indication of possible self-thinning in an experimental tree stand. Problem: Results from the ks.test and the shapiro.test are not comparable (see example of both tests). Tree height is a nice continuous