r

Redefine Data Frame in R

Hello. I have a data frame database$VAR which has values of 0's and 1's. How can I redefine the data frame so that the 1's are removed? Thanks! ...

Bootstrapping to compare two groups

In the following code I use bootstrapping to calculate the C.I. and the p-value under the null hypothesis that two different fertilizers applied to tomato plants have no effect in plants yields (and the alternative being that the "improved" fertilizer is better). The first random sample (x) comes from plants where a standard fertilizer h...

Coin Toss Plot [R]

From Feller (1950) An Introduction to Probability Theory: A path of length n can be interpreted as the record of an ideal experiment consisting of n successive tosses of a coin. If +1 stands for heads, then Sk equals the (positive or negative) excess of the accumulated number of heads over tails at the conclusion of the kth trial. Th...

basic R question on manipulating dataframes

I have a data frame with several columns. rows have names. I want to calculate some value for each row (col1/col2) and create a new data frame with the original row names. If I just do something like data$col1/data$col2 I get a vector with the results but lose the row names. i know it's very basic but I'm quite new to R. ...

"Object Moved" error in using the RCurl getURL function in order to access an ASP Webpage

I am trying to use the getURL function of RCurl Package in order to access an ASP Webpage as: my_url <- "http://www.my_site.org/my_site/main.asp?ID=11&amp;REFID=33" webpage <- getURL(my_url) but I get an Object Moved redirection error message like: "<head><title>Object moved</title></head>\n<body><h1>Object Moved</h1> This object...

How to run R script with gdb attached?

I have an R script that's usually started from the command line with arguments: ./script.R --width=10 It uses Rscript as interpreter: #!/usr/bin/env Rscript Unfortunately it gives me a segmentation fault when it executes my compiled C code in R using .C("compiled_function"). So how can I run my R script with the gdb debugger atta...

show multiple R graphics windows in (r)gedit

I'm using rgedit plugin for gedit. I would like to allow more than one graphic (plot) window to show at a time. Currently, whenever I plot(), the plot overwrites the previous plot window. ...

Stacked bar chart in R (ggplot2) with y axis and bars as percentage of counts

Hi, I'm a novice with ggplot2 and have a question about generating a stacked bar plot. I checked the book and the dedicated webpage, but can't solve the problem. I have two factors, one of which has 2 levels (presence-absence), the other 10 levels. Lets call these two "variable" and "fruit". I'd like to create a stacked bar plot where ...

How to upload a file to a server via FTP using R ?

The title says it all. ...

R - aggregating daily content

Hi, I've been attempting to aggregate (some what erratic) daily data. I'm actually working with csv data, but if i recreate it - it would look something like this: library(zoo) dates <- c("20100505", "20100505", "20100506", "20100507") val1 <- c("10", "11", "1", "6") val2 <- c("5", "31", "2", "7") x <- data.frame(dates = dates, val1=...

redefine length.character in R

Since length is a generic method, why can't I do length.character <- nchar ? It seems that strings are treated special in R. Is there a reason for that? Would you discourage defining functions like head.character and tail.character? ...

ggplot2: line connecting the means of grouped data

I'm trying to group one variable of my data by another and then plot a line through the means. It works fine when both variables are numbers. However, I'm having a problem when the grouping variable is a factor. I have a mock up below. x <- sample(1:3, 40, replace=T) y <- rnorm(40) df1 <- data.frame(x, y) qplot(x, y, data=df1) + stat_...

Why will WHERE statement not work in sqlQuery in RODBC?

We keep all our laboratory data in a Sybase database. When I want to do data manipulation and analysis I read the data into R with RODBC. library(RODBC) channellab <- odbcConnect("Labdata") indivs <-sqlQuery(channellab,'SELECT * from CGS.Specimen') So far so good, except that CGS.Specimen is a table for our entire lab holdings. There ...

Bound parameters in ROracle SELECT statements

When using ROracle in R, I want to bind some parameters to data, so I do this: > dbh <- dbConnect('Oracle', 'user/[email protected]:port/sid') > st <- dbPrepareStatement(dbh, statement="SELECT x FROM mytab WHERE id=:1", bind="character") > st <- dbExecStatement(st, data.frame(id=c("9ae", "1f3"), stringsAsFactors=F...

ordered factors in ggplot2 bar chart

I have a data frame with (to simplify) judges, movies, and ratings (ratings are on a 1 star to 5 star scale): d = data.frame(judge=c("alice","bob","alice"), movie=c("toy story", "inception", "inception"), rating=c(1,3,5)) I want to create a bar chart where the x-axis is the number of stars and the height of each bar is the number of r...

random sample from dataframe and output into excel

I'm taking a random sample from dataframe (a) I've got. The qualifier a[,1] is to be exported into excel. However I'm in trouble. str(a) 'data.frame': 2299 obs. of 5 variables: $ A : Factor w/ 2284 levels "01012223427",..: 1339 78 779 1590 1687 64 1034 633 1321 109 a[sample(a[,1],300),]->q This results in 300 rando...

Scanning an array in R

I use R and I have a long numeric vector. I would like to look for all the maximal continuous subranges in this vector, where all values are lower then some threshold. For example, if the given vector is 5 5 6 6 7 5 4 4 4 3 2 1 1 1 2 3 4 5 6 7 6 5 4 3 2 2 3 4 4 and my threshold is 4 (i.e., =<3), then the values that meet this conditi...

R Syntax Problem

Hi All, I am having trying to cat different strings to a file for different conditions using if - else statements: cat("<graph caption=\"ECG Data Wave\" subcaption=\"For Person's Name\" xAxisName=\"Time\" yAxisMinValue=\"-0.025\" yAxisName=\"Voltage\" decimalPrecision=\"5\" formatNumberScale=\"0\" numberPrefix=\"\" showNames=\"1\" sh...

Is there a way to check the spelling of words in a character vector?

The text to be checked is in Greek, but I would like to know if it can be done for English words too. My initial idea is described here, and I have already found a way to do it using VBA. But I wonder if there's a way to do it using R. If there isn't a way in R, do you think of something better than Excel-vba? ...

R graphics: Add labels to stacked bar chart

Hi, I am looking for a way to add labels, i.e. absolute values, into a stacked bar chart using the basic plot functions of R. The labels should be inside the stacked bars. Thank you! ...