Search results

  1. J

    create a variable (rowsums) by condition

    Hello, I am wondering if it is possible to compute a rowsums using a list, and also, filter the sum by a condition from a third variable. I thoght in something as ghj : data frame list_g=("va1","va2",var3") ghj$jkj[ ghj$var4=10 ]=apply(ghj[,list_g],1,rowsums) The syntax before clearly...
  2. J

    svydesign and prop tables: how to compute CVs and SE?

    Hello, I am in the need of estimate the CVs and SE from a proportion. I mean, I have a variable with categories. I need to obtain the errors from the proportions of each category over the total sum. I can total estimates flawlessly the CVs or SE with svytotal, but I'm missing something with the...
  3. J

    ggplot - graph bars and line

    Hi, I need to plot bars and line using the data frame named mydata2. I am able to plot only bars using : library(ggplot2) p <-ggplot(mydata, aes(as.character(months), y=values)) p +geom_bar(stat = "identity", aes(fill = type), width = 0.6, position="dodge")+ xlab("trimestres")+...
  4. J

    Aggregate by a data frame variable

    Hello, I want to perform the following aggregate: aggregate(fact~cis+sex,data=subset(bbdd,cis>0 ),FUN=sum) but using the vector zone to have multiples tables. I already did it with a loop, but that's not the purpose of R, i think: for (i in 1:max(zone) { nn=paste("base",i,sep="_")...
  5. J

    knitr and external R script

    R script BJsales out1=mean(BJsales) out2=BJsales[NROW(BJsales)] Rmarkdown --- output: html_document: df_print: paged pdf_document: default word_document: default --- ## Details ### The mean of the data was out1 and the last value was out2 Something like that I need to...
  6. J

    knitr and external R script

    Hi, I have a R script. My plan is to use rmarkdown and import some values and tables from the global environment produced by the R script. I've been trying to do that, but I always get errors. I mean, for example, how can I import the values from the vector "zxc" into knitr in order to print it...
  7. J

    Calibrate survey using rake

    Hello, I need to calibrate a survey using raking. I already declared the complex design here: des_survey <- svydesign(id= ~idd, strata= ~strata, data = datos, weights = ~ft, check.strata=TRUE ) options(survey.lonely.psu = "remove") options(digits = 10) However, when I run the rake process...
  8. J

    Tabulate two variables by a third one

    Hello, I'm trying to avoid a loop to do this zz=matrix(NA, nrow=40,ncol=1) for (i in 1:40) { wer=table(id[qwe==i],strata[qwe==i]) df=nrow(wer)-ncol(wer) zz[i]=df } The variable qwe goes from 1 to 40, and I need the nrow-ncol from a crossing two variables (id, strata) Is It possible to...
  9. J

    bootstrapping - change in time using complex survey

    Hi, My problem seems simple, but I'm a bit lost. I have two variables, X1 and Y1. X1 and Y1 are the way a product is classified by the team X1 and Y1. X1: team X1 coding Y1: team Y1 coding And I need to test if the change (relative) between t and t+12 is different or not when I compare X1 and...
  10. J

    lapply and svyratio

    Hello, I need to compute some ratios using a survey. I manage to calculate regional totals after especifying a list of variables (regions). Regions are dummies from 1 to 17, taking the value of 1 if the observation belongs to the region1. This code works. It computes totals by regions using the...
  11. J

    Matrix rownames from variable levelsof

    Hello, I'm writing a code and I need to name the matrix row names with the local created from levelsof applied to var1 (variable 1). I already created the matrix using as reference a local (levels) using levelsof length. I tried something simple as this matrix rownames=`levels' Stata returned...
  12. J

    concatenate - Loop with variables

    Forget this. With "lapply" I did it. By the way, I still need to concatenate the dummies to the original data frame...
  13. J

    concatenate - Loop with variables

    Hi, I need to obtain a set of dummies. Then I need to concatenate every one of them I generated in my simple loop. And that's what I can't figure it out. c=seq(from=1, to=200) region=round(runif(200,min=1,max=10),0) cise=round(runif(200,min=0,max=6),0) data=cbind(c,region,cise) attach(data)...
  14. J

    concatenate - Loop with variables

    Hello, I have a data frame. I generated some dummies using a simple loop. However, I can't concatenate the dummies to the original data frame. yyy=max(region) for (i in 1:yyy) { nam=paste("region",i,sep="") assign(nam,as.numeric(cise>0 & region==i))...
  15. J

    How can I report common strings in array/dataframe

    Thanks, Dason. You are very kind. I think this thread is solved.
  16. J

    How can I report common strings in array/dataframe

    Of course, dat <- data.frame(a = letters[1:5], b = letters[2:6], c = letters[3:7]) I need to perform some function to retrieve the non commons letters considering the three columns in order to export the non common letters to a vector or colum as: vector<-a, f, g I already know that using...
  17. J

    How can I report common strings in array/dataframe

    Your code worked great. One final question, what do I need to edit in order to obtain the opposite to the intersection? I mean, the rows that are not shared in every column? Thanks for your sintax, Dason. Very simple and fast.
  18. J

    How can I report common strings in array/dataframe

    I just need a vector reporting only the "strings" that exist, or are common, considering all the columns from the data frame or matrix. I don't care the row order of a "string" to report. Only the existence is the relevant. The example I provided with the images tries to explain that. Sorry if I...
  19. J

    How can I report common strings in array/dataframe

    Hello, I have no idea how to report in a vector the commons variables from a data.frame or matrix. I have a data many columns. In this example I show four columns with d1-d4 as names. So, how do I create a vector with the common strings? Something as this: It looks simple, but...
  20. J

    Loop exporting to excel file- writeWorksheetToFile

    I've made some test I found out that the package XLConnect isn't reliable when you try to make some loops. So, I just decided to append every database and after the last file is appended, I've exported using the XLConnect package. If you ask me how do I know the package XLConnect fails, It is...