Re: [R] Archive format

2017-04-08 Thread G . Maubach
Hi Joe, I have read your question with great interest. I am a little bit astonished to read about your project. There is a big national institute in Germany called GESIS (https://de.wikipedia.org/wiki/GESIS_%E2%80%93_Leibniz-Institut_f%C3%BCr_Sozialwissenschaften) which does the same job you a

[R] Antwort: Re: Antwort: Re: Way to Plot Multiple Variables and Change Color

2017-04-10 Thread G . Maubach
Hi Ulrik, many thanks for your reply. I had to take an unplanned break and was not in the office during the last two weeks. Thus my late reply. I followed your advice and converted the variable in argument "fill" to factor. Now the color change works: -- cut -- d_result <- structure(list("var

[R] Antwort: Re: Antwort: Re: Antwort: Re: Way to Plot Multiple Variables and Change Color (SOLVED)

2017-04-11 Thread G . Maubach
Hi David, many thanks for your answer. I followed your suggesting and came up with the following code: -- cut -- ggplot( d_result, aes(x = variable, y = n, fill = value)) + geom_bar( stat = "identity") + coord_cartesian(ylim = c(0,100)) + coord_flip() + scale_y_continuous(name =

[R] ggplot2: ..n.. and ..count.. in geom_text

2017-04-18 Thread G . Maubach
Hi All, I have the following code: -- cut (g03_02_p02 <- ggplot(data = d_kzb_input) + geom_bar( mapping = aes(x = v03_02_r01, y = round(..prop.. * 100, 0)), fill = c_ww_palette["blue"]) + scale_y_continuous(limits = c(0, c_y_limit)) + theme_classic() + ggtitle(paste0("Question 3

[R] Follow-up: RStudio: Place for Storing Options (as plain text)

2017-04-19 Thread G . Maubach
Hi All, some time ago I asded a question about the places where RStudio stores it configuration information. I came across this posting https://support.rstudio.com/hc/en-us/articles/206382178?version=1.0.136&mode=desktop explaining RStudio keybindings (predefined and customized). At the end of

[R] Multiple-Response Analysis: Cleaning of Duplicate Codes

2017-04-25 Thread G . Maubach
Hi All, in my current project I am working with multiple-response questions (MRSets): -- Coding -- 100 Main Code 1 110 Sub Code 1.1 120 Sub Code 1.2 130 Sub Code 1.3 200 Main Code 2 210 Sub Code 2.1 220 Sub Code 2.2 230 Sub Code 2.3 300 Main Code 3 310 Sub Code 3.1 320 Sub Code 3.2 The coding

[R] Antwort: Re: Multiple-Response Analysis: Cleaning of Duplicate Codes (SOLVED)

2017-04-26 Thread G . Maubach
Hi Bert, many thanks for your reply. I appreciate your help a lot. I would like to do the operation (= finding the duplicates) row-wise. During this night a solution showed up in my dreams :) Instead of using duplicates() to flag and filter the values I could use unique instead with the same r

[R] Antwort: Re: Multiple-Response Analysis: Cleaning of Duplicate Codes (SOLVED)

2017-04-26 Thread G . Maubach
Hi Bert, many thanks for your reply. I appreciate your help a lot. I would like to do the operation (= finding the duplicates) row-wise. During this night a solution showed up in my dreams :) Instead of using duplicates() to flag and filter the values I could use unique instead with the same r

[R] Factors and Alternatives

2017-05-09 Thread G . Maubach
Hi All, I am using factors in a study for the social sciences. I discovered the following: -- cut -- library(dplyr) test1 <- c(rep(1, 4), rep(0, 6)) d_test1 <- data.frame(test) test2 <- factor(test1) d_test2 <- data.frame(test2) test3 <- factor(test1, levels = c(0, 1),

[R] Antwort: Re: Factors and Alternatives

2017-05-09 Thread G . Maubach
Hi Bob, many thanks for your reply. I have read the documentation. In my current project I use "item batteries" for dimensions of touchpoints which are rated by our customers. I wrote functions to analyse them. If I create a factor before filtering and analysing I lose the original values of t

[R] Antwort: RE: Antwort: Re: Factors and Alternatives (SOLVED)

2017-05-09 Thread G . Maubach
Hi David, Hi Bob, many thanks for your help. Your solution - just to use all levels instead of just the one's found in the data - helped. The original code looked like this: -- cut -- c_v10_val_labs <- c( "1 = sehr gut", "2", "3", "4", "5", "6 = sehr schlecht" ) # where c_v10_val_labs

[R] Off-Topic: Project Organisation

2017-05-11 Thread G . Maubach
Hi All, this post is somewhat off-topic cause it deals with a meta issue related to project organisation instead of real R code. I have updated my blog concerning a possible directory and file structure for marketing research projects and data mining projects alike: https://github.com/gmaubach

[R] ggplot: Pie Chart with correct labels

2017-05-30 Thread G . Maubach
Hi All, I would like to do the following pie chart using ggplot from an official data source ( http://www.deutscheweine.de/fileadmin/user_upload/Website/Service/Downloads/Statistik_2016-2017-neu.pdf , Tab 8, Page 14): -- cut -- cat("# weinimport_piechart.R\n") # -- Input -

[R] purrr::pmap does not work

2017-06-07 Thread G . Maubach
Hi All, I try to do a scatterplot for a bunch of variables. I plot a dependent variable against a bunch of independent variables: -- cut -- graphics::plot( v01_r01 ~ v08_01_up11, data = dataset, xlab = "Dependent", ylab = "Independent #1" ) -- cut -- It is tedious to repeat the stateme

[R] Paths in knitr

2017-06-08 Thread G . Maubach
Hi All, I have to compile a report for the management and decided to use RMarkdown and knitr. I compiled all needed plots (using separate R scripts) before compiling the report, thus all plots reside in my graphics directory. The RMarkdown report needs to access these files. I have defined ```

Re: [R] Paths in knitr

2017-06-12 Thread G . Maubach
Hi Yihui, Hi Duncan, I corrected my typo. Unfortunately knitr did not find my plots in the directory where they reside which is different from the Rmd document. The documentation of knitr says: base.dir: (NULL) an absolute directory under which the plots are generate root.dir: (NULL) the root d

[R] Antwort: Re: Re: Paths in knitr

2017-06-12 Thread G . Maubach
Hi Yihui, I took root.dir and base.dir out. Everything works fine despite the change. I have implemented the solution Duncun suggested. I have difficulties with the scaling / image size in my report. Some plots are too big, some are too small. I need to adjust any plot. Steep learning curve :)

[R] WG: Fw: Re: rmarkdown and font size

2017-06-12 Thread G . Maubach
Hi Dan, Hi All, I read the below post. I am wondering how do I know which "keys" are available, e.g. "core.r" and "pre". Where kind I find the definition of what can be adjusted and which "words" to use? Kind regards Georg > Gesendet: Donnerstag, 08. Juni 2017 um 16:16 Uhr > Von: "Nordlund,

[R] Filtering String Variables

2016-05-23 Thread G . Maubach
# Hi All, # # I have the following data frame (example): Debitor <- c("968691", "968691", "968691", "A04046", "A04046", "L0006", "L0006", "L0006", "L0023", "L0023", "L0056", "L0056", "L0094", "L0094", "L0094", "L0124",

[R] WG: Filtering String Variables (SOLVED)

2016-05-23 Thread G . Maubach
Hi All, the solution for my question is as follows ## Filter duplicates and correpsonding non-duplicates ### To filter duplicates and their corresponding non-duplicates use the ### following code snippet: Debitor <- c("968691", "968691", "968691", "A04046", "A04046", "L0

[R] Creating a data frame from scratch

2016-05-24 Thread G . Maubach
Hi All, I need to create a data frame from scratch and fill variables created on the fly with values. What I have so far: -- schnipp -- # Example dataset gene <- c("ENSG0208234","ENSG0199674","ENSG0221622","ENSG0207604", "ENSG0207431","ENSG0221312","ENSG00134940305",

[R] Antwort: Re: Creating a data frame from scratch (SOLVED)

2016-05-25 Thread G . Maubach
Hi Dan, Hi All, many thanks for your help. Please find enclosed my little function for your use: -- cut -- #--- # Module: t_count_na.R # Author: Georg Maubach # Date : 2016-05-24 # Update

[R] Difference subsetting (dataset$variable vs. dataset["variable"]

2016-05-30 Thread G . Maubach
Hi All, I thought dataset$variable is the same as dataset["variable"]. I tried the following: > str(ZWW_Kunden$Branche) chr [1:49673] "231" "151" "151" "231" "231" "111" "231" "111" "231" "231" "151" "111" ... > str(ZWW_Kunden["Branche"]) 'data.frame':49673 obs. of 1 variable: $

[R] Variable labels and value labels

2016-05-31 Thread G . Maubach
Hi All, I am using R for social sciences. In this field I am used to use short variable names like "q1" for question 1, "q2" for question 2 and so on and label the variables like q1 : "Please tell us your age" or q2 : "Could you state us your household income?" or something similar indicating w

[R] Utility Functions

2016-05-31 Thread G . Maubach
Hi All, I was new to R and this list a couple of mounths ago. When processing my data I got tremendous support from R-Help mailing list. The solutions I have worked out with your help might be also helpful for others. I have put the solutions in a couple of small functions with documentation a

[R] Installing miniCRAN on Debian

2016-06-01 Thread G . Maubach
Hi All, I am installng miniCRAN on Debian GNU Linux 8 Jessie (Linux analytics7 4.5.0-0.bpo.2-amd64 #1 SMP Debian 4.5.4-1~bpo8+1 (2016-05-13) x86_64 GNU/Linux) and R 3.3.0 -- cut -- > sessionInfo() R version 3.3.0 (2016-05-03) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Lin

[R] Antwort: Re: Unable to update R software to 3.3.0

2016-06-01 Thread G . Maubach
Hi all, I did it today on Debian GNU Linux 8 Jessie this way: vim /etc/apt/sources.list deb http://cran.uni-muenster.de/bin/linux/debian jessie-cran3 ESC;:wq apt.get update apt-get install r-base r-base-dev This worked for me. When installing R packages from within R I found that R needed the

[R] Antwort: RE: Variable labels and value labels

2016-06-01 Thread G . Maubach
Hi Petr, I am looking for a general procedure that I can use with any package of R. As to my current experience it probably will happen that I need a procedure from another package than hmisc or memisc and the my solution shall work even than so that I do need to find another way to do it. Kin

[R] Antwort: Re: Variable labels and value labels

2016-06-01 Thread G . Maubach
Hi Jim, many thanks for the hint. When looking at the documentation I did not get how I do control which value gets which label. Is it possible to define it? Kind regards Georg Von:Jim Lemon An: g.maub...@weinwolf.de, r-help mailing list , Datum: 01.06.2016 03:59 Betreff:

[R] Merging variables

2016-06-06 Thread G . Maubach
Hi All, I merged two datasets: ds_merge1 <- merge(x = ds_bw_customer_4_match, y = ds_zww_customer_4_match, by.x = "customer", by.y = "customer", all.x = TRUE, all.y = FALSE) R created a new dataset with the variables customer.x and customer.y. I would like to merge these two variable back

[R] Antwort: RE: Merging variables

2016-06-06 Thread G . Maubach
Hi David, Hi Petr, many thanks for your help. With your hints I got the idea how I could do it and I came up with this solution: -- cut -- #--- # Module: t_merge_variables.R # Author: Georg Maubach # Dat

[R] Antwort: Re: Merging variables

2016-06-06 Thread G . Maubach
Hi Michael, yes, I was astonished about this behaviour either. I have worked with SPSS a lot - and that works different. I would like to share some of my data. Can you tell me how I can dump a dataset in a way that I can post it here as text? Kind regards Georg Von:Michael Dewey An:

[R] Antwort: RE: Merging variables

2016-06-06 Thread G . Maubach
Hi Petr, I would like to describe the data situation in brief: I have an business warehouse dataset (referred to as BW data) containing sales and an ERP customer master data dataset with additional information (referred to as ERP data). Though customer IDs and customer names are identical due

[R] Antwort: RE: Antwort: Re: Merging variables

2016-06-08 Thread G . Maubach
Hi Petr, thanks for your reply. I prepared little example for you: -- cut -- ds_temp_1 <- structure(list( CustId = c(1001, 1002, 1003, 1004, 1005, 1006), CustName = c("Miller", "Smith", "Doe", "White", "Black", "Nobody"), sales = c(100, 500, 300, 50, 700, 10) ),

[R] Warning message in openxlsx

2016-06-14 Thread G . Maubach
Hi All, I get the warning message Warning message: In styles$font : partial match of 'font' to 'fonts' when executing > xls_workbook <- t_create_workbook() > xls_sheetname <- "Kunden" > xls_ds_to_save <- ds_merge1 > xls_filename <- paste0(data_created, "_Merge1_BW-SAP-Kunden_cleaned.xlsx") >

[R] Installation of package "rio" broken

2016-06-14 Thread G . Maubach
Hi all, today I wanted to install package "rio". As it depends on package "feather" which is only available as source I have chosen to install "rio" from source. The installations fails with the following messages: -- cut -- * installing *source* package 'feather' ... ** Paket 'feather' erfolgr

[R] Building a binary vector out of dichotomous variables

2016-06-16 Thread G . Maubach
Hi All, I need to build a binary vector made of a set of dichotomous variables. What I have so far is: -- cut -- ds_example <- structure( list( year2013 = c(0, 0, 0, 1, 1, 1, 1, 0), year2014 = c(0, 0, 1, 1, 0, 0, 1, 1), year2015 = c(0, 1, 1, 1, 0, 1, 0

[R] Fw: Aw: Re: Building a binary vector out of dichotomous variables

2016-06-17 Thread G . Maubach
> Hi Tom, > > thanks for your reply. > > Yes, that's exactly what I am looking for. I did not know about the automatic > type conversion in R. > > #-- cut -- > ds_example <- > structure( > list( > year2013 = c(0, 0, 0, 1, 1, 1, 1, 0), > year2014 = c(0, >0,

[R] (Off-Topic] Introducing a new R Blog

2016-06-20 Thread G . Maubach
Hi All, today I would like to announce a now R blog. I contains a few entries about the findings during my course of studies and my daily work: https://github.com/gmaubach/R-Know-How/wiki/R-Blog I hope you'll find my hints usefull. In addition you could have a look at a small R collection of f

[R] Subscripting problem with is.na()

2016-06-23 Thread G . Maubach
Hi All, I would like to recode my NAs to 0. Using a single vector everything is fine. But if I use a data.frame things go wrong: -- cut -- var1 <- c(1:3, NA, 5:7, NA, 9:10) var2 <- c(1:3, NA, 5:7, NA, 9:10) ds_test <- data.frame(var1, var2) test <- var1 test[is.na(test)] <- 0 test # NA rec

[R] r_toolbox: Update

2016-06-23 Thread G . Maubach
Hi folks, I have updated the functions of the r_toolbox.R set of utilities: https://sourceforge.net/projects/r-project-utilities/files/?source=navbar Naming was changed with some functions to reflect similar functions in SAS or SPSS, e. g. t_n_miss, t_n_valid. In addition I added functions for

Re: [R] Subscripting problem with is.na()

2016-06-24 Thread G . Maubach
Hi Bert, many thanks for all your help and your comments. I learn at lot this way. My question was about is.na() at the first sight but the actual task looks like this: I have two variables in my customer data that signal if the customer accout was closed by master data management or by sales.

[R] Antwort: Fw: Re: Subscripting problem with is.na()

2016-06-27 Thread G . Maubach
Hi David, Hi Bert, many thanks for the valuable discussion on NA in R (please see extract below). I follow your arguments leaving NA as they are for most of the time. In special occasions however I want to replace the NA with another value. To preserve the newly acquired knowledge for me I wrot

[R] Antwort: RE: Antwort: Fw: Re: Subscripting problem with is.na()

2016-06-27 Thread G . Maubach
Hi Petr, many thanks for your reply and the examples. My subscripting problems drive me nuts. I have understood that dataset[variable] is semantically identical to dataset[, variable] cause dataset[variable] takes all cases because no other subscripts are given. Where can I lookup the rules w

[R] Antwort: RE: Antwort: Fw: Re: Subscripting problem with is.na()

2016-06-27 Thread G . Maubach
Hi All, Petr, Bert, David, Ivan, Duncan and Rui helped me to develop a function able to replace NA's in variables IF NEEDED: #--- # Module: t_replace_na.R # Author: Georg Maubach # Date : 2016-06

[R] Installing from source on Windows 7: tibble

2016-06-29 Thread G . Maubach
Hi All, I would like to install R packages from source on Windows 7 64-Bit. Currently my settings are: -- cut -- > sessionInfo() R version 3.3.0 (2016-05-03) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=German_Germany.

[R] Antwort: Re: Installing from source on Windows 7: tibble

2016-06-29 Thread G . Maubach
Hi Duncan, many thanks for your reply. I did insert die paths to the g++ compiler because I got the message about the not existent compiler. I took the directories for the compiler out again: C:\R-Project\Rtools\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Python 3.5\Scripts\;C:\P

[R] Antwort: Re: Antwort: Re: Installing from source on Windows 7: tibble [SOLVED]

2016-06-29 Thread G . Maubach
Hi Duncan, indeed, I did not see the other part of your message. I did BINPREF ?= C:/R-Project/Rtools/mingw_32/bin/ COMPILED_BY = g++ # instead of gcc-4.9.3 in "C:\R-Project\R-3.3.0\etc\i386\Makeconf" and BINPREF ?= C:/R-Project/Rtools/mingw_64/bin/ COMPILED_BY = g++ # instead of gcc-4.9.3 i

[R] Antwort: Re: Antwort: Re: Antwort: Re: Installing from source on Windows 7: tibble [RE OPENED]

2016-06-29 Thread G . Maubach
Hi Duncan, I would not have changed the COMPILED_BY option unless I thought I have to. In my "C:\R-Project\Rtools\mingw_32\bin" I have c++.exe g++.exe gcc.exe i686-w64-mingw32-c++.exe i686-w64-mingw32-g++.exe i686-w64-mingw32-gcc-4.9.3.exe i686-w64-mingw32-gcc.exe In my "C:\R-Project\Rtools\m

[R] Writing a formula to Excel

2016-06-30 Thread G . Maubach
Hi All, I am using excel.link to work seemslessly with Excel. In addition to values, like numbers and strings, I would like to insert a full operational formula into a cell. xlc["G14"] <- print(paste("=G9*100/G6"), quote = FALSE) The strings is put into the cell, but the cell is not evaluate

Re: [R] Documenting data

2016-06-30 Thread G . Maubach
Hi Pito, Dear Readers, as other have already mentioned, there are good practices for documenting code and data. I would like to summarize them and add a few not mentioned earlier: 1. You should have always two things: your raw data and your R script/s. The raw data is immutable whereas the R sc

Re: [R] Documenting data

2016-06-30 Thread G . Maubach
Hi Bert, Hi Readers, I did not know much about attributes in R and how to use them. If it is that flexible you are right and I have learnt something. Kind regards Georg > Gesendet: Donnerstag, 30. Juni 2016 um 20:06 Uhr > Von: "Bert Gunter" > An: g.maub...@gmx.de > Cc: "Pito Salas" , "R Help"

[R] Dump of new Methods

2016-07-04 Thread G . Maubach
Dear Readers, Hi All, to drive my R knowlegde a bit further I followed the advice of some of you by reading Chambers: Programming with data. I tried some examples from the book: -- cut -- setClass("track", representation (x = "numeric", y = "numeric")) trac

[R] Antwort: Re: Dump of new Methods (SOLVED)

2016-07-04 Thread G . Maubach
Hi Bert, many thanks. Found them. Kind regards Georg Von:Bert Gunter An: g.maub...@weinwolf.de, Datum: 04.07.2016 16:43 Betreff:Re: [R] Dump of new Methods ?getwd Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and st

[R] Antwort: Re: dplyr : row total for all groups in dplyr summarise

2016-07-05 Thread G . Maubach
Hi guys, I checked out your example but I can't follow the results.: > mtcars %>% + group_by (am, gear) %>% + summarise (n=n()) %>% + mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%")) %>% + ungroup() %>% + mutate(row.tot = sum(n)) Source: local data frame [4 x 5] am gear

[R] WG: Fw: Re: dplyr : row total for all groups in dplyr summarise

2016-07-06 Thread G . Maubach
Hi All, if I run the suggested code mtcars %>% group_by (am, gear) %>% summarise (n = n()) %>% mutate(rel.freq = paste0(round(100 * n / sum(n), 0), "%")) %>% ungroup() %>% plyr::rbind.fill(data.frame(n = nrow(mtcars), rel.freq = "100%”)) I

[R] Formatting ggplot2 graph

2016-07-06 Thread G . Maubach
Hi All, my current code looks lke this: freq_ls <- structure(list(Var1 = c("zldkkd", "aakdkdk", "aaakdkd", "aaieiwo", "vöalsl", "ssddkdk", "glowowp", "laoiw", "ruklow", "rolsl", "delk

[R] Choropleth: Turnover by ZipCode

2016-07-11 Thread G . Maubach
Hi All, Dear Readers, I need to create a choropleth graph with turnover by zipcode. This is what I have so far: # Not run (Begin) # Install packages if needed # install.packages(pkgs = c("maptools", "rgdal", "RColorBrewer", "grDevices")) # Not run (End) # Load libraries library(maptools); libr

[R] R Toolbox (Release 2 of 2016-07-21)

2016-07-21 Thread G . Maubach
Hi All, I have uploaded a new release of the R Toolbox. R Toolbox is a collection of simple but useful functions which I developed for myself to shorten the develoment process. Currently all functions use base R. No other packages are needed. One exception is "t_openxlsx" cause this module dea

[R] Error when installing packages

2016-07-26 Thread G . Maubach
Hi All, I try to install packages on Debian GNU Linux 8 (Kernel 3.16.0-4-amd64). My sessionInfo() is R version 3.3.1 (2016-06-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux 8 (jessie) locale: [1] LC_CTYPE=de_DE.UTF-8 LC_NUMERIC=C [3] LC_TIME=de_

[R] Spread data.frame on 2 variables

2016-07-28 Thread G . Maubach
Hi All, I need to spread a data.frame on 2 variables, e. g. "channel" and "unit". If I do it in two steps spreads keeps all cases that does not look like the one before although it contains the same values for a specific case. Here is what I have right now: -- cut -- test1$dummy <- 1 test2 <-

[R] Antwort: Re: Re: Spread data.frame on 2 variables (SOLVED)

2016-08-02 Thread G . Maubach
Hi Ulrik, many thanks for your help. The problem was that R regards a dataset with a combination like caseID custID channel unit 1 100010 10 2 100020 10 3 100020

[R] Accessing an object using a string

2016-08-15 Thread G . Maubach
Hi All, I would like to access an object using a sting. # Create example dataset var1 <- c(1, 2, 3) var2 <- c(4, 5, 6) data1 <- data.frame(var1, var2) var3 <- c(7, 8, 9) var4 <- c(10, 11, 12) data2 <- data.frame(var3, var4) save(file = "c:/temp/test.RData", list = c("data1", "data2")) # Define

[R] Antwort: Accessing an object using a string (SOLVED)

2016-08-15 Thread G . Maubach
Hi All, I found the function get() which returns an object. My whole function looks like this: -- cut -- #--- # Module: t_load_dataset.R # Author: Georg Maubach # Date : 2016-08-15 # Update

[R] Antwort: Re: Accessing an object using a string

2016-08-15 Thread G . Maubach
Hi Greg and all others who replied to my question, many thanks for all your answers and help. Currently I store all my objects in .GlobalEnv = Workspace. I am not yet familiar working with different environments nor did I see that this would be necessary for my analysis. Could you explain why

[R] Installation of rJava fails

2016-08-17 Thread G . Maubach
Hi All, I try to install RWeka on Debian GNU Linux 8 Jessie (uname -a: 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64) which has a dependency to "rJava". I did apt-get install openjdk-8-jre which went OK. Java is installed in: /var/lib/dpkg/alternatives/java /usr/lib/

[R] Iteration over variables

2016-09-06 Thread G . Maubach
Hi All, I would like to write a program that iterates over a set of dynamically generated variables and produces some stats or prints parts of the data. # --- data v_turnover_2011 <- c(10, 20, 30, 40 , 50) v_customer_2011 <- c(0, 1, NA, 0, 1) v_turnover_2012 <- c(10, 20, 30, 40 , 50) v_customer_

[R] Putting a bunch of Excel files as data.frames into a list fails

2016-09-28 Thread G . Maubach
Hi All, I need to read a bunch of Excel files and store them in R. I decided to store the different Excel files in data.frames in a named list where the names are the file names of each file (and that is different from the sources as far as I can see): -- cut -- # Sources: # - http://stackove

[R] Filtering Cases with != NA

2015-12-17 Thread G . Maubach
Dear All, I am new to "R" and search for a solution to exclude cases if a certain variable contains NA for a case. Example No Name Turnover 1 Smith 1500 2 Mayor 200 3 Miller 4 Batic 750 I would like to create a subset excluding case 3 Miller NA. I tried to following: new_dataset <- subset(d

[R] Merging Data Sets with Full Outer Join

2016-04-20 Thread G . Maubach
Hi All, I would like to match some datasets. Both deliver variables AND cases which might or might not be present in all datasets: This sequence Kunden <- Kunden_2011 Kunden <- merge(Kunden, Kunden_2012, by.x = "Debitor", by.y = "Debitor") Kunden <- merge(Kunden, Kunden_2013,

[R] Creating variables on the fly

2016-04-22 Thread G . Maubach
Hi all, I would like to use a loop for tasks that occurs repeatedly: # Groups # Umsatz <= 0: 1 (NICHT kaufend) # Umsatz > 0: 2 (kaufend) for (year in c("2011", "2012", "2013", "2014", "2015")) { paste0("Kunden$Kunde_real_", year) <- (paste0("Kunden$Umsatz_", year) <= 0) * 1 +

[R] Antwort: Fw: Re: Creating variables on the fly (SOLVED)

2016-04-25 Thread G . Maubach
Hi Don, Hi to all readers, many thanks for all your answers and all your help. I adapted Don's code to my data and Don's code does the trick: str(Kunden01) for (year in 2011:2015) { Reeller_Kunde <- paste0("Reeller_Kunde_", year) Umsatz <- paste0("Umsatz_", year) cat('Creating', Reeller_K

[R] Missing Values in Logical Expressions

2016-04-26 Thread G . Maubach
Hi All, I need to evaluate missing values in my data. I am able to filter these values and do simple statistics on it. But I do need new variables based on variables with missing values in my dataset: Check_Kunde_2011 <- ifelse(is.na(Umsatz_2011) == TRUE & Kunde_2011 == 1, 1, 0) Check_Kunde_20

[R] Antwort: RE: Missing Values in Logical Expressions

2016-04-27 Thread G . Maubach
Hi Petr, Hi Jim, many thanks for your help. Today I constructed a sample dataset and tested your suggestions. Everything worked OK. Then I took the code and testet on the original data. And - it worked OK this morning also. I went back to my script of Thuesday and ran it again. OK. Then I used

[R] R Script Template

2016-04-27 Thread G . Maubach
Hi All, I am addressing this post to all who are new to R. When learing R in the last weeks I took some notes for myself to have code snippets ready for the data analysis process. I put these snippets together as a script template for future use. Almost all of the given command prototypes are

[R] Interdependencies of variable types, logical expressions and NA

2016-04-28 Thread G . Maubach
Hi All, my script tries to do the following on factors: > ## Check for case 3: Umsatz = 0 & Kunde = 1 > for (year in 2011:2015) { + Umsatz <- paste0("Umsatz_", year) + Kunde <- paste0("Kunde01_", year) + Check <- paste0("Check_U_0__Kd_1_", year) + + cat('Creating', Check, 'from', Umsatz,

[R] Antwort: Re: R Script Template

2016-04-28 Thread G . Maubach
Hi All, please find enclosed the missing attachment. Kind regards Georg -- cut -- #-[ Header ] -- # Program : Framework for R scripts # Author: Georg Maubach # Date : 2016-03-03 # Update: 2016-04-27

[R] Antwort: Re: selecting columns from a data frame or data table by type, ie, numeric, integer

2016-05-03 Thread G . Maubach
Hi All, Hi Carl, I am not sure if this is useful to you, but I followed your conversation and thought of you when I read this: for (i in 1:ncol(dataset)) { if(class(dataset) == "character|numeric|factor|or whatsoever") { dataset[, i] <- as.factor(dataset[, i]) } } Source: Zumel, Nina / M

[R] Antwort: Antwort: Re: selecting columns from a data frame or data table by type, ie, numeric, integer

2016-05-04 Thread G . Maubach
Hi Martin, many thanks for your answer and your broad explanation. I am a newbie to "R" and got help on this list and thought I could give something back what looked OK to me. regarding 0) You're right, it's pseudo code. I assumed that anybody on the list would be able to adapt the code to th

[R] sink(): Cannot open file

2016-05-10 Thread G . Maubach
Hi All, I would like to route the output to a file using sink(). When using the example from the ?sink documentation: sink("sink-examp.txt") i <- 1:10 outer(i, i, "*") sink() unlink("sink-examp.txt") ## capture all the output to a file. zz <- file("all.Rout", open = "wt") sink(zz) sink(zz, type

[R] Antwort: Re: sink(): Cannot open file

2016-05-10 Thread G . Maubach
Hi Jim, thanks for your reply. ad 1) "all.Rout" was created in the correct directory. It exists properly with correct file properties on Windows, e.g. creation date and time and file size information. ad 2) I can not access the file with Notepad.exe directly after it was created by R. The er

[R] Antwort: Re: Re: sink(): Cannot open file

2016-05-10 Thread G . Maubach
Hi Jim, I tried: sink("all.Rout") try(log("a")) sink() The program executes without warning or error. The file "all.Rout" is begin created. Nothing will be written to it. The file is accessable rights after the execution of the program by notepad.exe. The program zz <- file("all.Rout", open

[R] Antwort: Re: Antwort: Re: Re: sink(): Cannot open file

2016-05-10 Thread G . Maubach
Hi Sarah, John, Jim, Hi All, I have set my envrionment variable path <- file.path("H:", "2016", "Analysis") setwd(dir = path) This works well cause the file is created in that directory. I have tried close(zz) unlink(zz) and neither worked nor did it work out using them together. I had this

[R] Antwort: Re: Re: Antwort: Re: Re: sink(): Cannot open file

2016-05-11 Thread G . Maubach
Hi Sarah, yes, I followed your suggestion. If I do exactly what is in the example of the documentation: sink("C:/Temp/sink-examp.txt") i <- 1:10 outer(i, i, "*") sink() unlink("C:/Temp/sink-examp.txt") it does not write anything, i. e. no file is created in "C:/Temp/". The script is executed w

[R] Antwort: Re: Antwort: Re: Re: sink(): Cannot open file

2016-05-11 Thread G . Maubach
Duncan, thanks for the hint. I have done it correctly in R fashion ## capture all the output to a file. zz <- file("C:/Temp/all.Rout", open = "wt") sink(zz) sink(zz, type = "message") try(log("a")) ## back to the console sink(type = "message") sink() unlink("C:/Temp/all.Rout") But the error per

[R] Antwort: Re: Antwort: Re: Antwort: Re: Re: sink(): Cannot open file (SOLVED)

2016-05-12 Thread G . Maubach
Hi Henrik, Jim, Sarah, Duncan, Hi All, I have tried the built-in solution using PowerShell: $lockedFile="C:\Windows\System32\wshtcpip.dll" Get-Process | foreach{$processVar = $_;$_.Modules | foreach{if($_.FileName -eq $lockedFile){$processVar.Name + " PID:" + $processVar.id}}} It did not show

[R] Antwort: Antwort: Re: Re: Antwort: Re: Re: sink(): Cannot open file

2016-05-12 Thread G . Maubach
Hi Martin, many thanks for following-up on my question. I did it again: ## capture all the output to a file. zz <- file("C:/Temp/all.Rout", open = "wt") sink(zz) sink(zz, type = "message") try(log("a")) ## back to the console sink(type = "message") sink() close(zz) This works. I tried several

[R] How to plot a bunch of dichotomous code variables in one plot using ggplot2

2016-10-05 Thread G . Maubach
Hi All, I have a bunch of dichotomous code variables which shall be plotted in one graph using one of their values, this is "1" in this case. The dataset looks like this: -- cut -- var1 <- c(1,0,1,0,0,1,1,1,0,1) var2 <- c(0,1,1,1,1,0,0,0,0,0) var3 <- c(1,1,1,1,1,1,1,1,0,1) ds <- data.frame(var

[R] Antwort: RE: How to plot a bunch of dichotomous code variables in one plot using ggplot2

2016-10-05 Thread G . Maubach
Hi Bob, Hi John, Hi readers, many thanks for your reply. I did barplot(colSums(dataset %>% select(FirstVar:LastVar))) and it worked fine. How would I do it with ggplot2? Kind regards Georg Von:"Fox, John" An: "g.maub...@weinwolf.de" , Kopie: "r-help@r-project.org" Datum: 05.

[R] Documenting a function using roxygen2

2016-10-11 Thread G . Maubach
Hi All, I began to document my functions using roxygen2. This is an example of a function I would like to write for training and testing purposes: t_simple_table <- function(variable, useNA = TRUE, print = FALSE) { #' @title Create a simp

[R] Visibility of libraries called from within functions

2016-10-13 Thread G . Maubach
Hi All, in my R programs I use different libraries to work with Excel sheets, i. e. xlsx, excel.link. When running chunks of code repeatedly and not always in the order the program should run for development purposes I ran into trouble. There were conflicts between the methods within these fun

[R] Antwort: Re: Visibility of libraries called from within functions

2016-10-13 Thread G . Maubach
Hi Duncan, many thanks for your reply. Your suggestion of using requireNamespace() together with explicit namespace calling using the "::" operator is what I was looking for: -- cut -- f_test <- function() { requireNamespace("openxlsx") cat("Loaded packages AFTER loading library")

[R] Antwort: Re: Antwort: Re: Visibility of libraries called from within functions

2016-10-13 Thread G . Maubach
Von:Duncan Murdoch An: g.maub...@weinwolf.de, r-help@r-project.org, Datum: 13.10.2016 12:34 Betreff:Re: Antwort: Re: [R] Visibility of libraries called from within functions On 13/10/2016 6:21 AM, g.maub...@weinwolf.de wrote: > Hi Duncan, > > many thanks for your reply. > > Y

[R] Reshaping geographic data

2016-10-17 Thread G . Maubach
Hi All, I need to reshape an ESRI shape file: http://arnulf.us/PLZ and resp http://www.metaspatial.net/download/plz.tar.gz I found an instruction for T-SQL Server: https://blog.oraylis.de/2010/05/german-map-spatial-data-for-plz-postal-code-regions/ How can I do this using R? Kind regards Geo

[R] Storing long string with white space in variable

2016-10-19 Thread G . Maubach
Hi All, I would like to store a long string with white space in a variable: -- cut -- # Create README.md readme <- "--- title: "Your project title here" author: "Author(s) name(s) here" date: "Current date here" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo

[R] openxlsx Error: length of rows and cols must be

2016-11-15 Thread G . Maubach
Hi All, when using -- cut -- number_style <- openxlsx::createStyle( numFmt = "COMMA" ) openxlsx::addStyle( wb = xlsx_workbook, sheet = "Kundenliste", style = number_style, rows = 2:nrow(customer_list), cols = 4:5 ) --cut -- I get the error

[R] Different results when converting a matrix to a data.frame

2016-11-16 Thread G . Maubach
Hi All, I build an empty dataframe to fill it will values later. I did the following: -- cut -- matrix(NA, 2, 2) [,1] [,2] [1,] NA NA [2,] NA NA > data.frame(matrix(NA, 2, 2)) X1 X2 1 NA NA 2 NA NA > as.data.frame(matrix(NA, 2, 2)) V1 V2 1 NA NA 2 NA NA -- cut -- Why does data.

[R] for loop is looping only once

2016-11-17 Thread G . Maubach
Hi All, I need to execute a loop on variables to compute several KPIs. Unfortunately the for loop is executed only once for the last KPI given. The code below illustrates my current solution but is not completely necessary to spot the problem. I just give an idea what I am doing overall. Looks

[R] Antwort: Re: for loop is looping only once [SOLVED]

2016-11-17 Thread G . Maubach
Hi Ulrik, oh no! What a mistake did I make. But I definitely did not see the failure. Many thanks for helping me. Kind regards Georg Von:Ulrik Stervbo An: g.maub...@weinwolf.de, r-help@r-project.org, Datum: 17.11.2016 12:24 Betreff:Re: [R] for loop is looping only once

[R] openxlsx: No Formatting of Numbers (TEXT ONLY)

2016-12-05 Thread G . Maubach
Hi All, Dear Readers, I am using openxlsx to export data to Microsoft Excel 2013, 32-Bit, German Version: --- schnipp --- library("openxlsx") dataset <- structure( list( a = c(1126039.81, 45636.44, 14847.41), b = c(1194447.5, 88310.53, 18699.68), c = c(1560307.73, 34203

  1   2   >