[R] Sample of a subsample

2017-09-25 Thread David Studer
Hello everybody! I have the following problem: I'd like to select a sample from a subsample in a dataset. Actually, I don't want to select it, but to create a new variable sampleNo that indicates to which sample (one or two) a case belongs to. Lets suppose I have a dataset containing 40 cases:

[R] calculate factor scores

2015-11-09 Thread David Studer
Hello everybody, I have a problem regarding factor analysis: As I am using the hetmat()-function from the polycor-package in order to calculate different kinds of correlation coefficients automatically* I cannot obtain factor scores using fit$scores. The problem is that I am using the

[R] aggregating variables (sum within groups)

2015-02-26 Thread David Studer
Hello everybody! I have a (probabely very easy) problem. Even though I was looking in several r-books I could not find a suitable function to this problem, that's why I hope that someone here could help me: # Sample data: group-c(A,A,A,B,B,C,C,C) var1-c(1,0,0,1,1,0,NA,1) var2-c(0,1,NA,0,1,1,0,0)

[R] factor levels numeric values

2014-11-12 Thread David Studer
Hi everybody, I have another question (to which I could not find an answer in my r-books. I am sure, it's not a great issue, but I simply lack of a good idea how to solve this: One of my variables gets imported as a factor instead of a numeric variable. Now I have a... Factor w/ 63 levels

[R] Counting within groups / means by groups

2014-11-10 Thread David Studer
Hi everyone! I have problems finding a solution to the following two problems: My sample-dataframe consists of two variables group and value: group-c(A, A, A, B, B, B, B, C) value-c(1,3,2,2,2,4,4,1) df-as.data.frame(cbind(group, value)) Problem 1: ** Now I'd like to count the number

[R] Crime hotspot maps (kernel density)

2013-11-08 Thread David Studer
Hi everybody, does anyone of you know how to create a (crime) hotspot map using R? Are there any packages or do you know any ressources? It should be something like this: http://www.caliper.com/Maptitude/Crime/MotorVehicleTheft2.png (but it doesnt necessarely have to be a map) Many thanks,

[R] reduce three columns to one with the colnames

2013-05-13 Thread David Studer
Hello everybody, I have three variables blue, green and red containing values 0 (no) and 1 (yes). How can I easily create another variable colors with the values blue, green and red? I hope that you can understand my question and appreciate any solutions or hints! Thank you! David

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread David Studer
. That might be: c(red[red], green[green], blue[blue]) Cheers, Bert On Mon, May 13, 2013 at 7:36 AM, Pascal Oettli kri...@ymail.com wrote: Hi, ?rgb HTH Pascal 2013/5/13 David Studer stude...@gmail.com Hello everybody, I have three variables blue, green and red

[R] Color spalettes for black/white printing

2013-03-05 Thread David Studer
Hi everybody! Does anyone know a good way to color my images so that when I print them out on a non-color-printer the colors used can be distinguished well? As I have many categories I would not want to assign the colors c(black, grey, white) by hand. Thank you! [[alternative HTML

[R] urgent: question concerning data manipulation

2013-03-04 Thread David Studer
Hello everyone! Does anyone of you know how I could solve the following problem. I guess, it is not a very difficult question, but I simply lack of the right idea: I have a dataset containing data of convictions. This dataset contains 4 columns: - personId: individual number that identifies the

[R] recoding variables again :(

2013-01-30 Thread David Studer
Hello everybody! I have again a rather simple question concerning recoding of variables: I have a variable/data-frame column BIRTHPLACE containing abbreviations of the 26 swiss counties (AG, AI, AR, BE, ZH, ... ) as well as international country codes (USA, GER, ESP, etc.) and another variable

[R] Recoding variables (without recode() )

2013-01-25 Thread David Studer
Hi everybody! I have a rather simple question: # play data persId-c(1,2,3,1,4,5,2) varA-c(11,12,13,12,14,15,10) df-as.data.frame(cbind(persId, varA)) Now I'd like to create a new columns (df$new) according to the value of df$VarA. For example df$new1 should be 1 if df$varA==2 or df$new2 should

[R] missing values are not allowed in subscripted assignments of data frames

2013-01-21 Thread David Studer
Hello everybody! I am trying to replace community numbers with community names (character). I am using the following code: data[data$commNo==786, commNo]-Name of the Community Unfortunately, I get the error message missing values are not allowed in subscripted assignments of data frames

[R] importing a SAS syntax-files (value labels)

2013-01-17 Thread David Studer
Hello everybody, I imported an SAS data-file into R. open.sas7bdat() did not work, so I had to convert it to csv first. Now I would like to recode the value values into factors. Unfortunately I only have a SAS syntax file, having this form: proc format; value $resstatus 'B'=

[R] p-values from lm()

2012-06-14 Thread David Studer
Hi everyone! Can anyone tell me, how to obtain p.values from a linear model? Example: mod1-lm(dV~iV1+iV2) Now, I can get the coefficients with mod1$coef But how can I get p-values? ($p.values seems to work with cor.test() only) Thank you! [[alternative HTML version deleted]]

[R] divide factor in n equal groups?

2012-06-07 Thread David Studer
Could anyone please tell me what is the most elegant way to divide an ordinal variable in equal groups? (as cut() does with continous variables) for example I'd like to have the factor educational level in three groups low medium and high Thank you! David [[alternative HTML version

[R] regression methods for rare events?

2012-06-04 Thread David Studer
Hi everybody! I have a sample with n=2.000. This sample contains rare events (10, 20, 30 individuals with a specific illness). Now I'd like to do a logistic regression in order to identify risk factors. I have several independent variables on an interval scale. Does anyone know whether the

[R] inter-item-correlation-table

2012-05-18 Thread David Studer
Hi everybody! Does anyone know how to obtain a inter-item-correlation-table (with p-values or significance-levels)? (as SPSS does, either spearman or pearson) Repeatedly using cor.test() is pretty exhausting as the table size increases... Thank you! David [[alternative HTML version

[R] y-axis-problem (barplots)

2012-05-07 Thread David Studer
Hi everybody! I would like to plot a barplot, but, unfortunately, when I change the y-axis limits the bars do not start at 0 any more but get negative: # # Data (just a short example): a-c(1.61, 2.1) b-c(1.5, 1.9) c-c(1.85, 2.2) d-c(1.63, 2.3)

[R] Transform dataframe

2012-04-22 Thread David Studer
Hi everyone! I have to following question: I have three items that had to be ordered (e.g. three persons were rating var1 on the first rank): var1 var2 var3 123 213 132 123 Now I'd like to have the data.frame the other way round, so that the ranks are in the

[R] ggplot2-Problem (plot different variables)

2012-04-20 Thread David Studer
Hi everyone! I have the following difficulties using ggplot2 # My Data data-as.data.frame(cbind(a=c(1,1,2,2,2,2,3,3,4), b=c(1,2,3,3,4,4,4,4,4))) And I would like to plot the frequency-distributions of both variables in one plot as lines. For both variables the values (1-4) should be on the

[R] Recode Variable

2012-04-12 Thread David Studer
Hello everybody, I know this is pretty basic stuff, but could anyone explain me how to recode a single value of a variable into a missing value? I used to do it like this: myData[myData$var1==5;var1]-NA # recode value 5 into NA But the column var1 already contains NAs, which

[R] Multiple line-plot

2012-02-16 Thread David Studer
Hello everybody! I have again another newbie-question. I was trying to plot three curves within one single plot: Crime development (relative frequencies) according to the hours of tv consume per week (high/low/all together). Here are the data: par(mfrow=c(1,1)) # Data input

[R] Multiple linear Regression: Standardized Coefficients

2012-02-15 Thread David Studer
Hello everybody, Can anyone tell me, how to obtain standardized regression coefficients (betas) for my independent variables when doing a multiple linear regression? height-c(180,160,150,170,190,172) sex-c(1,2,2,1,1,2) age-c(40,20,30,40,20,25) fit-lm(height~age+sex) summary(fit) I already

[R] Change dataframe-structure

2012-02-13 Thread David Studer
Hello everybody, I have the following problem and have no idea how to solve it: In my dataframe I have six columns representing six societal problems (p1, p2, ..., p6). The values are ranks between 1 (worst problem) and 6 (best problem) p1 p2 p3 p4 p5 p6 1 3 2 5 4 6 2 3 1 6

[R] factor level for non-existing value

2012-02-09 Thread David Studer
Hello everybody! Let's assume I have the following factor with it's levels: a-factor(c(2,3,3,2,4,2,3,2,2,2,3,2,3)) mydata-data.frame(a) When I plot the vector a using barplot(table(mydata$a) unfortunately the value 1 does not show up, as it does not appear in my data. But still, it

[R] how to select columns

2012-01-30 Thread David Studer
Hello, I have the following question: when creating a data.frame a1-c(1,2,3) a2-c(1,2,3) c-data.frame(a1,a2) I can select columns using an index like: c[,1:2] Is this possible too when using column-names? (something like c(,a1:a2), which doesn't work) Alternative question: Is there a function