Displaying 20 results from an estimated 7000 matches similar to: "subsetting - questions"
2012 Nov 22
4
Data Extraction
Hello,
I would appreciate if someone could help me resolve the following:
1. df1[!is.na( X1 | X2 | X3 | X4 | X5),][,1:5] # This does not work
2. Is these message harmful? The following object(s) are masked from 'df1 (position 3)':
X1, X2, X3, X4, X5
Thanks,
Pradip Muhuri
#Reproducible Example
set.seed(5)
df1<-data.frame(matrix(sample(c(1:10,NA),100,replace=TRUE),ncol=5))
2012 Nov 20
4
github
Hello,
I would like to learn how to set up Github/repository and upload/update files and am looking for "Github for Dummies". Any help will be appreciated.
Thanks,
Pradip
2012 Oct 10
2
svyplot
Hello,
Using the svyplot () function, I have plotted four graphs that are saved in four different .png files.
I am looking for examples how to redraw the same four graphs within grid viewports so that they stay together on a page. The goal is to create one .png file that will include all four graphs (2 rows, 2 columns).
Any help would be appreciated.
Thanks,
Pradip
Pradip K. Muhuri,
2012 Oct 02
2
svyby and make.formula
Hello,
Although my R code for the svymean () and svyquantile () functions works fine, I am stuck with the svyby () and make.formula () functions. I got the following error messages.
- Error: object of type 'closure' is not subsettable # svyby ()
- Error in xx[[1]] : subscript out of bounds # make.formula ()
A reproducible example is appended below.
I would appreciate if
2012 Dec 31
3
cut ()
Hello List,
My goal is to create a 5 category variable (p1_st_data$ob_mrj_cat), based on the p1_st_data$obt_mrj_p variable, using the following code for 50 States and District of Columbia (N=51).
p1_st_data$ob_mrj_cat <- cut (p1_st_data$obt_mrj_p, quantile (p1_st_data$obt_mrj_p, (0:5/5), include.lowest=TRUE))
The issue is that, for Utah, I am getting an <NA> instead of (42,48.7] in
2011 May 24
1
R in batch mode
Hi Everyone,
I am a new R user and trying to run R jobs in batch mode.
Robert Muenchen (2009), in his book "R for SAS and SPSS Users", has suggested writing a small batch file like mR.bat as shown below:
"C:\Program File\R\R-2.10.0\bin\Rterm.exe" --no-restore --no-save < %1 > %1.Rout 2>& 1
Could anyone tell me in which directory or subdirectory I should
2012 Nov 22
1
Data Extraction - benchmark()
Hi Berend,
I see you are one of the contributors to the rbecnhmark package.
I am sorry that I am bothering you again. I have tried to run your code (slightly tweaked) involving the benchmark function, and I am getting the following error message. What am I doing wrong?
Error in benchmark(d1 <- s1(df), d2 <- s2(df), d3 <- s3(df), d4 <- s4(df), :
could not find function
2012 Nov 20
2
kinitr
Hello,
I am an Intro-level R and ggplot2 user and looking for resources to self teach dynamic report generation in R using knitr. Any advice would be highly appreciated.
Thanks,
Pradip
2012 Oct 05
1
svyhist
Hello,
I was trying to draw histograms of age at death and got the following 2 error messages:
1) Error in tapply(1:NROW(x), list(factor(strata)), function(index) { :
arguments must have same length
2) Error in findInterval(mm[, i], gx) : 'vec' contains NAs
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) :
2013 Jan 08
2
Applying a user-defined function
Hello List,
My goal is to apply a user-defined function on several columns of a data frame. When testing the code on a reproducible example below, I get the following error message.
> #now Write a new function using the above cut ()/quantile function to apply on different columns of the data frame
>
> CutQuintiles <- function(x) {
+ cut (test1$x,quantile (test1$x,
2012 Oct 14
2
svyhist and svyboxplot
Hello,
The following code is expected to produce 4 charts. But, I only get charts 1,2 ,& 4, NOT CHART # 3.
For Chart# 3, I am getting the following error message: Error in tapply(1:NROW(x), list(factor(strata)), function(index) { : arguments must have same length
I would appreciate if someone could help me resolve the issue.
Thanks,
Pradip
# BELOW IS THE REPRODUCIBLE EXAMPLE
setwd
2012 Nov 03
1
Logical vector-based extraction
Hello,
The most part of the program works except that the following logical variable does not get created although the second logical variable-based extraction works.
I don't understand what I am doing wrong here.
state_pflt200 <- df$p_fatal <200
df[state_pflt200, c("state.name","p_fatal")]
I would appreciate receiving your help.
Thanks,
Pradip Muhuri
2011 Jun 01
1
Contributed Packages - Hmisc & survey
Hello List,
Could someone tell why I can't install the Himsc and survey packages for R version 2.13.0 (2011-04-13)? What am I doing wrong here?
Thanks,
Pradip
> install.packages ("Hmisc", dependencies=TRUE)
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://watson.nci.nih.gov/cran_mirror/bin/windows/contrib/2.13
2012 Dec 14
1
format.pval () and printCoefmat ()
Hi List,
My goal is to force R not to print in scientific notation in the sixth column (rel_diff - for the p-value) of my data frame (not a matrix).
I have used the format.pval () and printCoefmat () functions on the data frame. The R script is appended below.
This issue is that use of the format.pval () and printCoefmat () functions on the data frame gives me the desired results, but coerces
2012 Dec 08
4
read.table()
Hi List,
I have spent more than 30 minutes, but failed to read in this file using the read.table() function. I could not figure out how to fix the following error.
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1 did not have 6 elements
Any help would be be appreciated.
Thanks,
Pradip Muhuri
####### below is the reproducible example
xd1 <-
2012 Oct 01
3
merge.zoo returns unmatched dates
Sorry for the lack of reproducible data, but this seems to be a problem inherent to my dataset and I can't figure out where the issue is.
I have several data frames set up as a time series with identical POSIXct date formats. If I keep the original data in data frame format and merge them using base merge- everything is perfect and everyone is happy.
If I transform the data frames to zoo
2011 Oct 19
1
Subsetting data by eliminating redundant variables
Dear All,
I am new to R, I have one question which might be easy.
I have a large data with more than 250 variable, i am reducing number of
variables by redun function as in the example below,
n <- 100
x1 <- runif(n)
x2 <- runif(n)
x3 <- x1 + x2 + runif(n)/10
x4 <- x1 + x2 + x3 + runif(n)/10
x5 <- factor(sample(c('a','b','c'),n,replace=TRUE))
x6 <-
2014 Nov 14
1
file.copy
Hello,
Here is something (file.copy) trivial but does not seem to work. I could not figure out what I am doing wrong.
The R script below creates folders (fromFolder and toFolder) and finds the list of files (list.of.files) to be copied to the toFolder, which I have verified using the print () command. But, the issue is that the file.copy() command does not work.
Both the R.script and the
2014 Nov 10
2
range () does not remove NA's with complete.cases() for dates (dplyr/mutate)
Hello,
The range() with complete.cases() removes NA's for the date variables that are read from a data frame. However, the issue is that the same function does not remove NA's for the other date variable that is created using the dplyr/mutate(). The console and the reproducible example are given below. Any advice how to resolve this issue would be appreciated.
Thanks,
Pradip Muhuri
2008 Mar 29
1
Tabulating Sparse Contingency Table
I have a sparse contingency table (most cells are 0):
> xtabs(~.,data[,idx:(idx+4)])
, , x3 = 1, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 31
2 0 0 112
3 0 0 94
, , x3 = 2, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 0
2 0 0 0
3 0 0 0
, , x3 = 3, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 0
2 0 0 0
3 0 0 0
, , x3 = 1, x4