R: Export and import a list to .txt file
This post suggests a way to write a list to a file.lapply(mylist, write, "test.txt", append=TRUE, ncolumns=1000) The issue with this technic is that part of the information of the list (the structure...
View ArticleFInd max Value by multiple colums as new column [duplicate]
I have a df like this:x = c(1,1,2,2,1 ) y = c(2,2,3,3,1 ) z = c(4,3,2,1,1 ) df<-data.frame(x,y,z) Now I have to find the max value in column z. My Output should looks like this: x y z max 1 2 4 4 1...
View ArticleFind point in dataframe where (col_1[ i ], col_2[ i ]) = (col_1[ j ], -col_2[...
There might be an obvious solution to this that I have missed but here goes:Consider the data frame below. I wish to create a column with TRUE/FALSE values, where the value is TRUE whenever the...
View ArticleWhat is the correct/standard way to check if difference is smaller than...
I often end up in situations where it is necessary to check if the obtained difference is above machine precision. Seems like for this purpose R has a handy variable: .Machine$double.eps. However when...
View ArticleHow to create a function with already written for-loop to automatically...
I have a df with fixed columns and unfixed row number. I created empty vectors and populate R commands to create vectors on its own once I use eval(parse(text = someVector)). What I did with for-loop...
View ArticleR - elegant way to select multiple variables in model like rpart or train
I want to use around 50 variable columns of my data as factors for my model and try to figure out an elegant way instead of using a long list of all variables.rpart(output_variable ~ Variable1 +...
View ArticleIfelse function in R doesn't work for dummy variable creation
I'm trying to create a dummy variable in R. Specifically, a variable (post) that takes the value 1 if the date corresponds to any of the listed values and 0 otherwise. I use the ifelse function which...
View ArticleConditional replacing of values ina a variable based on valuse in multiple...
I have a following line of code which replaces a value in a variable (var2) based on a value in other variable (var1) df$var2[df$var1 > 0] <- NA However I would like to extend this and replace...
View Articleupload files within nested folders in AWS S3 using R
I am looking a way where I can upload files with in a nested folder using R ProgrammingI tried below functions which uploads either file or folder from aws.s3 packagelibrary("aws.s3")...
View ArticleEach row of the input matrix needs to contain at least one non-zero entry
I have this issue when I run this chunk of codetext_lda <- LDA(text_dtm, k = 2, method = "VEM", control = NULL) I have the next mistake "Each row of the input matrix needs to contain at least one...
View ArticleRandom effect with gam() with betar family in R
I'm having trouble with my gam() analysis with betar family and the weird thing is that it worked perfectly before. After I restarted R, all kinds of error and warning messages showed up.I'm analysing...
View ArticleR Download table from webpage with RCurl
I'm trying to download a table from a html-site by using the RCurl::getURL()-function. The problem is that the following error appears:theurl <-...
View ArticleGgplot2 change the position of y axis values after removing gridlines
I want to create a heatmap in ggplot2 without the gridlines. I removed them using the theme function and panel.grid arguments, but it leaves the space between the y axis values and the plot: I tried to...
View ArticleHow do I make a binary matrix comparing several columns
I'm new to programming and R.I have a data like this in columns:C1 C2 C3 C4 C5 Apple Apple Banana Banana Banana Orange Orange Orange I want to make a binary matrix comparing all the columns to C1 where...
View ArticleR plottinjg polynomial regression line
I try to plot a polynomial regression line but the plotted line does not make sense. I use the iris dataset from the package datasets. This is my code:library(datasets) data2 <- iris[iris$Species !=...
View ArticleSpeeding up linear model fitting on complete pairwise observations in large...
I have a numeric data.frame df with 134946 rows x 1938 columns. 99.82% of the data are NA. For each pair of (distinct) columns "P1" and "P2", I need to find which rows have non-NA values for both and...
View ArticleCalculate the mean of one column from several CSV files
I have over 300 CSV files in a folder (named 001.csv, 002.csv and so on). Each contains a data frame with a header. I am writing a function that will take three arguments: the location of the files,...
View ArticlePattern changes doesn't aggregate rows with same char strings [duplicate]
I generate reports wherein I update/replaces certain details using gsub and %in% operator. Issue is after replacing certain string, the associated numerical values doesn't aggregate, when I use "match"...
View ArticleCan we track system logging and system logout time in R shiny
For the purpose of tracking my application, I have incorporated logging events in my application. It is tracking all information. But I need to put app opening time and opp closing time. Is it possible...
View ArticleHow I can take mean for different subsets of a specific column in a data.table?
Given a sample data frame:dt <- data.table(value=1:10,start=c(1,4,5,8,6,3,2,1,9,4),finish=c(3,7,8,9,10,10,4,10,10,8))I want to add a new column which may be named as mean_column. i'th row of this...
View Article