Re: [R] Invert Likert-Scale Values
Alexis and John, To reverse a Likert like item, subtract the item from the maximum acceptable value + the minimum acceptable value, That is, if x <- 1:8 xreverse <- 9-x Bill At 2:16 PM -0700 8/4/07, Alexis Delevett wrote: >Thank you John, that should definitely do the trick! > >Furthermore, I believe that this will help me research >the available resources more effectively in the future >-- instead of researching a specific problem (e.g., >"invert Likert-Scale items"), I might try starting out >with a more general problem (like "recode values") in >order to work my way towards a solution. > > > >--- John Kane <[EMAIL PROTECTED]> wrote: > >> Will ?recode in the car package do what you want? >> x <- 1:4 >> recode(x, "1='4';2='3' ;3='2'; 4='1'") >> >> >> --- Alexis Delevett <[EMAIL PROTECTED]> wrote: >> >> > Hi! >> > >> > I am using R to process some community survey >> data. >> > Several item responses are recorded via a 7-point >> > Likert-Scale. As I have coded the responses, 1 >> > represents high agreement, and 7 high >> disagreement. >> > This of course impacts the coefficients in a >> linear >> > regression (of example agreement to >> self-perception >> > measures on housing satisfaction). For some >> > purposes, in order to make the coefficients more >> > accessible to the reader, I would like to invert >> the >> > item values, i.e. to arrive at 1 for high >> > disagreement, and 7 for high agreement (such that >> > the linear regression would express something like >> > "the higher the agreement on A, the greater the >> B). >> > >> > Is there an already existing function for this, or >> > do I use a custom replace loop in R? >> > >> > Thank you, Alexis >> > >> > >> > - >> > >> > [[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 >> > and provide commented, minimal, self-contained, >> > reproducible code. >> > >> >> >> >>Get news delivered with the All new Yahoo! >> Mail. Enjoy RSS feeds right on your Mail page. >> Start today at >> http://mrd.mail.yahoo.com/try_beta?.intl=ca >> > >__ >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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for statistics: http://personality-project.org/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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] nearest correlation to polychoric
Jens, An alternative solution to the improper matrix problem is to do a principal factor solution rather than a maximum likelihood factor analysis solution. In the following discussion, I am using the factor.pa (principal factor) function from my psych package. Using your test set pr <- structure(c(1, 0.477, 0.644, 0.478, 0.651, 0.826, 0.477, 1, 0.516, 0.233, 0.682, 0.75, 0.644, 0.516, 1, 0.599, 0.581, 0.742, 0.478, 0.233, 0.599, 1, 0.741, 0.8, 0.651, 0.682, 0.581, 0.741, 1, 0.798, 0.826, 0.75, 0.742, 0.8, 0.798, 1), .Dim = c(6, 6)) I did a factor.pa(pr,2) and got Loadings: PA1 PA2 [1,] 0.52 0.54 [2,] 0.13 0.92 [3,] 0.56 0.49 [4,] 0.97 0.11 [5,] 0.63 0.58 [6,] 0.73 0.70 PA1 PA2 SS loadings2.472 2.217 Proportion Var 0.412 0.369 Cumulative Var 0.412 0.781 This compares to a factanal solution on the nearcor solution nr <- nearcor(pr)$cor f2 <- factanal(cov=nr, factors=2) Loadings: Factor1 Factor2 [1,] 0.735 0.388 [2,] 0.868 0.123 [3,] 0.534 0.523 [4,] 0.151 0.986 [5,] 0.508 0.660 [6,] 0.740 0.669 Factor1 Factor2 SS loadings 2.407 2.295 Proportion Var 0.401 0.382 Cumulative Var 0.401 0.784 The factor congruence of the two solutions is round(factor.congruence(f2,p2),2) PA1 PA2 Factor1 0.74 0.99 Factor2 1.00 0.68 However, when I do the same analysis on your second demo set, in one run I got a Haywood case for the principal factors. f2 <- factor.pa(hcor,2,n.obs=400) Loadings: PA1 PA2 x10.87 x20.65 x3 -0.10 0.64 x40.56 y1 0.51 y2 0.63 y3 0.78 y4 1.13 PA1 PA2 SS loadings2.56 1.917 Proportion Var 0.32 0.240 Cumulative Var 0.32 0.560 but not for the factanal of the nearcor solution for the hcor problem: ncor <- nearcor(hcor)$cor m2 <- factanal(covmat=ncor,factors=2,n.obs=400) Loadings: Factor1 Factor2 [1,] 0.899 [2,] -0.168 0.569 [3,] 0.647 [4,] 0.583 [5,] 0.468 [6,] 0.683 [7,] 0.877 -0.100 [8,] 0.997 Factor1 Factor2 SS loadings 2.486 1.907 Proportion Var 0.311 0.238 Cumulative Var 0.311 0.549 However, once again, the factor congruence coefficients are very good: round(factor.congruence(m2,f2),2) PA1 PA2 Factor1 0.99 -0.09 Factor2 -0.09 1.00 Then, I did a number of runs comparing principal axes to the hetcor data (what you call hcor), factanal to the original data ( what you call xcor, and factanal solutions to the nearcor solution (ncor). The general pattern is that principal axes of the polychoric (hcor) matrix tends to match the factanal solutions to the original data better than factanal of the nearcor matrix does the original matrix. round(factor.congruence(f2,n2),2) #compare principal axes to mle of nearcor solution Factor1 Factor2 PA10.980.17 PA20.180.99 >round(factor.congruence(f2,x2),2) >#compare principal axes to mle of original data Factor1 Factor2 PA10.920.07 PA20.100.95 >round(factor.congruence(n2,x2),2) >#compare mle of original to mle of nearcor Factor1 Factor2 Factor10.920.02 Factor20.030.94 Thanks for posting the nearcor algorithm and function. At 8:42 PM +0200 7/13/07, Jens Oehlschlägel wrote: >Dimitris, > >Thanks a lot for the quick response with the >pointer to posdefify. Using its logic as an >afterburner to the algorithm of Higham seems to >work. > >Martin, > >> Jens, could you make your code (mentioned >>below) available to the community, or even >>donate to be included as a new method of >>posdefify() ? > >Nice opportunity to give-back. Below is the R >code for nearcor and .Rd help file. A quite >natural place for nearcor would be John Fox' >package polycor, what do you think? > >John? > >Best regards > >Jens Oehlschlägel {nearcor function and help file deleted --- see original posting} Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for statistics: http://personality-project.org/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 and provide commented, minimal, self-contained, reproducible code.
[R] strange behavior in data frames with duplicated column names
Dear R gurus, There is an interesting problem with accessing specific items in a column of data frame that has incorrectly been given a duplicate name, even though addressing the item by row and column number. Although the column is correctly listed, an item addressed by row and column number gives the item with the correct row and the original not the duplicated column. Here are the instructions to get this problem x <- matrix(seq(1:12),ncol=3) colnames(x) <- c("A","B","A") #a redundant name for column 2 x.df <- data.frame(x) x.df#the redundant name is corrected x.df[,3]#show the column -- this always works x.df[2,3] #this works here #now incorrectly label the columns with a duplicate name colnames(x.df) <- c("A","B","A") #the redundant name is not detected x.df x.df[,3] #this works as above and shows the column x.df[2,3]#but this gives the value of the first column, not the third <--- rownames(x.df) <- c("First","Second","Third","Third") #detects duplicate name x.df x.df[4,] #correct second row and corrected column names! x.df[4,3]#wrong column x.df #still has the original names with the duplication and corresponding output: > x <- matrix(seq(1:12),ncol=3) > colnames(x) <- c("A","B","A") #a redundant name for column 2 > x.df <- data.frame(x) > x.df#the redundant name is corrected A B A.1 1 1 5 9 2 2 6 10 3 3 7 11 4 4 8 12 > x.df[,3]#show the column -- this always works [1] 9 10 11 12 > x.df[2,3] #this works here [1] 10 > #now incorrectly label the columns with a duplicate name > colnames(x.df) <- c("A","B","A") #the redundant name is not detected > x.df A B A 1 1 5 9 2 2 6 10 3 3 7 11 4 4 8 12 > x.df[,3] #this works as above and shows the column [1] 9 10 11 12 > x.df[2,3]#but this gives the value of the first column, not the >third <--- [1] 2 > rownames(x.df) <- c("First","Second","Third","Third") #detects >duplicate name Error in `row.names<-.data.frame`(`*tmp*`, value = c("First", "Second", : duplicate 'row.names' are not allowed > x.df A B A 1 1 5 9 2 2 6 10 3 3 7 11 4 4 8 12 > x.df[4,] #correct second row and corrected column names! A B A.1 4 4 8 12 > x.df[4,3]#wrong column [1] 4 > x.df #still has the original names with the duplication > unlist(R.Version()) platform archos "i386-apple-darwin8.9.1" "i386" "darwin8.9.1" system status major "i386, darwin8.9.1" "Patched" "2" minor year month "5.0" "2007" "04" day svn rev language "25" "41315" "R" version.string "R version 2.5.0 Patched (2007-04-25 r41315)" > Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for statistics: http://personality-project.org/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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] How-To construct a cov list to use a covariance matrix in factanal?
Alistair, > >I have worked through the examples. They work because the covmat >were produced by the cov.wt which provides output as a list object. >I am trying to construct my own list object to use as the covmat. >There are no obvious instructions on how to do this. > >So, here is what I have done so far. > >I reconstructed the covariance matrix in the example and created a dataframe: > > > testmatrix > general picture blocks maze reading vocab >1 24.641 5.991 33.520 6.023 20.755 29.701 >2 5.991 6.700 18.137 1.782 4.936 7.204 >3 33.520 18.137 149.831 19.424 31.430 50.753 >4 6.023 1.782 19.424 12.711 4.757 9.075 >5 20.755 4.936 31.430 4.757 52.604 66.762 >6 29.701 7.204 50.753 9.075 66.762 135.292 > >and then used this to construct a list object like the output from >the example; > >> tstcov<- list(cov=testmatrix, center=c(0,0,0,0,0), n.obs=112) > >I tested to see whether my list object looked like the examples > >> tstcov >$cov > general picture blocks maze reading vocab >1 24.641 5.991 33.520 6.023 20.755 29.701 >2 5.991 6.700 18.137 1.782 4.936 7.204 >3 33.520 18.137 149.831 19.424 31.430 50.753 >4 6.023 1.782 19.424 12.711 4.757 9.075 >5 20.755 4.936 31.430 4.757 52.604 66.762 >6 29.701 7.204 50.753 9.075 66.762 135.292 > >$centers >[1] 0 0 0 0 0 > >$n.obs >[1] 112 > >It looks the same. So I then used this list as the argument in >factanal and get the error message. > >> factanal(factors=2, covmat=tstcov, rotation="varimax") >Error in sqrt(diag(cv)) : Non-numeric argument to mathematical function > >I know that what you see of a list is not necessarily all that is >there. So, I figure I am missing some part of the object that makes >this list suitable for use by factanal. > So, I hope this is enough detail. Any thoughts would be appreciated. >-- >Dr Alistair Campbell, PhD >Senior Lecturer in Clinical Psychology >School of Psychology >James Cook University Townsville Queensland Australia The call to factanal requires you to specify that you have a covariance matrix (covmat). Using your matrix and specifying two factors: test.df general picture blocks maze reading vocab 1 24.641 5.991 33.520 6.023 20.755 29.701 2 5.991 6.700 18.137 1.782 4.936 7.204 3 33.520 18.137 149.831 19.424 31.430 50.753 4 6.023 1.782 19.424 12.711 4.757 9.075 5 20.755 4.936 31.430 4.757 52.604 66.762 6 29.701 7.204 50.753 9.075 66.762 135.292 > test.mat <- as.matrix(test.df) > tf <- factanal(factors=2,covmat=test.mat) > tf Call: factanal(factors = 2, covmat = test.mat) Uniquenesses: general picture blocksmaze reading vocab 0.455 0.589 0.218 0.769 0.052 0.334 Loadings: Factor1 Factor2 1 0.499 0.543 2 0.156 0.622 3 0.206 0.860 4 0.109 0.468 5 0.956 0.182 6 0.785 0.225 Factor1 Factor2 SS loadings 1.858 1.724 Proportion Var 0.310 0.287 Cumulative Var 0.310 0.597 The degrees of freedom for the model is 4 and the fit was 0.0572 Bill > -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ __ 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] Making a case for using R in Academia
Charles, As a psychologist in one of departments that you are trying to send your Hanover undergrads to for grad school let me say that 1) my various colleagues use SPSS, JMP, SAS and R. 2) I teach R as a supplement to my section of the undergraduate research methods course and in the advanced undergraduate course in personality research. For both of these I have prepared short tutorials that get them up and running very rapidly. 3) At the graduate level, in my psychometrics course, all my examples are done in R, but most of the students do the work in SPSS or JMP. (Although today, a 2nd year clinical student gave a wonderful talk about her data which she had analyzed in R, having just started using it last week.) 4) In terms of using R in psychological research, a recent paper of mine in Motivation and Emotion used John Fox's wonderful sem package and we also included an appendix with the R code for the simulations that we had run. Why did I want to buy LISREL when I had sem? (We do have a site license for LISREL just in case I wanted to use it.) 5) As further evidence that editors in the social sciences accept analyses done in R, I have a chapter in press in a handbook in personality research that includes an appendix in R on how to do simulated experiments and then how to analyze the data. So, you can tell your colleagues that at least some social science departments think highly of undergrads who know R. In answer to your does anyone have any statistics on the use of R in the social sciences? I don't know. Would not knowing SPSS put students at a disadvantage? No. I agree with Harold Doran that just knowing SPSS would put them at a disadvantage. Bill >As a addendum to all this, this is one of the responses I got from >one of my colleagues: > >"The problem with R is that our students in many social science >fields, are expected to know SPSS when they go to graduate school. >Not having a background in SPSS would put these students at a >disadvantage." > >Is this really the case? Does anyone have any such statistics? > >Charilaos Skiadas >Department of Mathematics >Hanover College >P.O.Box 108 >Hanover, IN 47243 > >__ >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. -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ __ 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] Question about variable selection
Dear Wensui, What you are asking about is called in psychology a "suppressor" variable: a predictor variable unrelated to the criterion but correlated with the other predictors. (X1 in the following example) Although it has a zero relationship with the DV, it does "really" help to predict the DV by removing extraneous variance from the other IVs. (I am not going to touch the Wittgenstein issue of truth here). Should it be included in the predictor set? Yes. Is there any easy way to find all possible suppressors? No. Consider the following: #demonstration of "suppressor effects" library(mvtnorm) sigma <- matrix(c(1,.5,0,.5,1,.5,0,.5,1),ncol=3) my.data <- data.frame(rmvnorm(1000,sigma=sigma)) names(my.data) <- c("X1", "X2", "Y") round(cor(my.data),2) summary(lm(Y~ X1 + X2,data= my.data)) which produces X1 X2 Y X1 1.00 0.45 -0.04 X2 0.45 1.00 0.51 Y -0.04 0.51 1.00 > summary(lm(Y~ X1 + X2,data= my.data)) Call: lm(formula = Y ~ X1 + X2, data = my.data) Residuals: Min 1Q Median 3Q Max -2.09350 -0.58069 0.02280 0.53436 3.02017 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.028070.02557 1.0980.273 X1 -0.328490.02813 -11.680 <2e-16 *** X2 0.656660.02861 22.951 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.8081 on 997 degrees of freedom Multiple R-Squared: 0.3465, Adjusted R-squared: 0.3452 F-statistic: 264.4 on 2 and 997 DF, p-value: < 2.2e-16 At 3:22 PM -0500 2/18/06, John Fox wrote: >Dear Wensui, > >I don't think that it's possible to answer these questions mechanically, >especially if you're interested in the "true" relationship between the >response and a set of explanatory variables. If, however, you have a pure >prediction problem, then variable selection is a more reasonable approach, >as long as it's done carefully (in my opinion). > >I don't see how resampling and repeatedly examining the marginal >relationship between Y and an X is relevant to the question of whether there >is a partial relationship in the absence of a marginal relationship. (This >is close to what Wittgenstein once called buying two copies of the same >newspaper to see whether what was said in the first one is true.) After all, >as I said (and as you understand), the partial and marginal relationship can >differ -- so evidence about the marginal relationship is not necessarily >relevant to inference about the partial relationship. (As well, >bootstrapping a linear least-squares regression likely isn't going to give >you much additional information anyway.) > >Regards, > John > > >John Fox >Department of Sociology (discussion of interaction from Andy Liaw) > > > > From: Wensui Liu > > > > > > > > > > Dear Lister, > > > > > > > > > > I have a question about variable selection for regression. > > > > > > > > > > if the IV is not significantly related to DV in the bivariate > > > > > analysis, does it make sense to include this IV into the > > > full model > > > > > with multiple IVs? > > > > > > > > > > Thank you so much! -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ __ 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] White Noise
At 1:38 PM + 1/22/06, Laura Quinn wrote: >I'm wanting to create a series of near-identical matrices via the addition >of "white noise" to my starting matrix. Is there a function within R which >will allow me to do this? > >Thank you If the starting matrix is symmetric, see mvrnorm in the MASS package. -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ __ 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 read an excel data into R?
Ling, If any column has text with spaces between words, this will lead to the "more columns ..." problem. Delete the spaces and try again. e.g., if the Excel file is Var1Var2Var3 text1 2 more text 3 4 yet more5 6 and more7 8 blahblah9 10 On a Mac, this will lead to the error message "Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 1 did not have 4 elements" (which I believe is the equivalent message to what you are getting on a PC) But, if your remove the blanks in column 1, this reads as > x <- read.table("test.txt",header=T) > x Var1 Var2 Var3 1 text12 2 moretext34 3 yetmore56 4 andmore78 5 blahblah9 10 with no error message. Alternatively, for small files, if using a PC try copying the Excel spreadsheet to your clipboard and x <- read.table(file("clipboard"), header = TRUE) or, if using a Mac x <- read.table(pipe("pbpaste"), header = TRUE) Bill At 8:38 PM -0400 6/22/05, Wensui Liu wrote: >Ling, > >You might take a look at the function read.xls() in gdata library. > >HTH. > > >On 6/22/05, Ling Jin <[EMAIL PROTECTED]> wrote: >> Hi all, >> >> Does anybody know the easiest way to import excel data into R? I copied >> and pasted the excel data into a txt file, and tried read.table, but R >> reported that >> >> Error in read.table("data_support.txt", sep = " ", header = T) : >> more columns than column names >> >> Thanks! >> > > Ling >> -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ __ 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] Dta structure of LOADINGS class in factanal
At 9:44 AM -0400 4/7/05, Tamas Gal wrote: Hi R users, I need some help in the followings: I'm doing factor analysis and I need to extract the loading values and the Proportion Var and Cumulative Var values one by one. Here is what I am doing: fact <- factanal(na.omit(gnome_freq_r2),factors=5); fact$loadings Loadings: Factor1 Factor2 Factor3 Factor4 Factor5 b1freqr2 0.246 0.486 0.145 ... b9freqr2 0.148 0.449 0.103 0.327 Factor1 Factor2 Factor3 Factor4 Factor5 SS loadings 1.294 1.268 1.008 0.927 0.730 Proportion Var 0.144 0.141 0.112 0.103 0.081 Cumulative Var 0.144 0.285 0.397 0.500 0.581 I can get the loadings using: fact$loadings[1,1] [1] 0.2459635 but I couldn't find the way to do the same with the Proportion Var and Cumulative Var values. Although not pretty, try colSums(fact$loading*fact$loading)/dim(fact$loading)[1] for the proportion Var and cumsum(colSums(fact$loading*fact$loading)/dim(fact$loading)[1]) to get the cumulative Var values Bill -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ __ 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] using "mean" in by(x,y,mean)
Dear list friends I fail to understand how to find means for multiple groups using the by() function. Help would be appreciated. Thanks. Bill x <- runif(20,0,10) group <- rep(c("A","B"),10) df <-data.frame(x,group) #df#show the data rm(x,group) attach(df) sd(x) # sd is defined mean(x) #so is mean by(x,group,sd) #this works for both groups by(x,group,mean) #this does not produces this output: x <- runif(20,0,10) group <- rep(c("A","B"),10) df <-data.frame(x,group) #df#show the data rm(x,group) attach(df) sd(x) # sd is defined [1] 2.952699 mean(x) #so is mean [1] 5.026441 by(x,group,sd) #this works for both groups INDICES: A [1] 2.813504 INDICES: B [1] 3.236663 by(x,group,mean) #this does not Error in FUN(X[[as.integer(1)]], ...) : couldn't find function "FUN" I am using a Mac OS 10.3.4 running R 1.9.1 -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Department of Psychology, Northwestern University Personality Project: http://personality-project.org/personality.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
Re: [R] problem with loadURL -- claims newer version used- fixed
big5r.txt is delimited by CR not LF, and as R writes it as a binary file, that's not the file that got saved. Thanks. That was the problem. I was transferring the files from my Mac to my web server (also a Mac) using Interarchy. It was putting in CRs rather than LFs (the Interarchy options were "old Mac cr" vs. Unix (lf)"). Changing that transfer option makes it work. Same problem with the header on big5r. Try some octal dumps and find out which step is changing the file. BTW, I would use load(url(someURL)) these days. load(url(someURL)) works (once I fixed the transfer to the server), although I used the other form because I was following the help for load. Perhaps the ?load comments could be modified to suggest load(url(someURL)) instead of suggesting loadURL(someURL). Thanks for the very rapid response. Bill On Mon, 10 May 2004, William Revelle wrote: Dear list, I am trying to prepare a handout showing how to use R for factor analysis. As part of the exercise I want to save a correlation matrix on a tutorial web page. I can save with no problem (saving locally and then transferring to the web site). Although I can load() the local file, I am having problems getting loadURL to read the remote file. I have tried saving it as an ascii file or just using the default format. Using R 1.9.0 on a Mac with OS 10.3 I first saved the file: save(big5r,file="big5r.txt",ascii=TRUE) and save(big5r,file="big5r") I can load either version from a local file using load(). I then have moved these files to a webserver and tried to load them using the loadURL() command. Using loadURL() I get the following message >loadURL("http://personality-project.org/r/datasets/big5r";) #the default format Error: restore file may be from a newer version of R -- no data loaded >loadURL("http://personality-project.org/r/datasets/big5r.txt";) #ascii format Error: restore file may be from a newer version of R -- no data loaded I can list the second file using a web browser and I can move the first file back to my machine and load it locally. My problem seems to be with loadURL. Any help would be appreciated. Bill -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [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 -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Department of Psychology, Northwestern University Personality Project: http://personality-project.org/personality.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] problem with loadURL -- claims newer version used
Dear list, I am trying to prepare a handout showing how to use R for factor analysis. As part of the exercise I want to save a correlation matrix on a tutorial web page. I can save with no problem (saving locally and then transferring to the web site). Although I can load() the local file, I am having problems getting loadURL to read the remote file. I have tried saving it as an ascii file or just using the default format. Using R 1.9.0 on a Mac with OS 10.3 I first saved the file: save(big5r,file="big5r.txt",ascii=TRUE) and save(big5r,file="big5r") I can load either version from a local file using load(). I then have moved these files to a webserver and tried to load them using the loadURL() command. Using loadURL() I get the following message >loadURL("http://personality-project.org/r/datasets/big5r";) #the default format Error: restore file may be from a newer version of R -- no data loaded loadURL("http://personality-project.org/r/datasets/big5r.txt";) #ascii format Error: restore file may be from a newer version of R -- no data loaded I can list the second file using a web browser and I can move the first file back to my machine and load it locally. My problem seems to be with loadURL. Any help would be appreciated. Bill -- ---- William Revelle http://pmc.psych.northwestern.edu/revelle.html Department of Psychology, Northwestern University Personality Project: http://personality-project.org/personality.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