Re: [R] Split a DF on Date column for each single year

2019-03-16 Thread Rainer Schuermann
In your sample data.frame, MyDate and MyDes are factors; is that what you want? rs On Samstag, 16. März 2019 01:40:01 CET Ek Esawi wrote: > Hi All— > > I have a data frame with over 13000 rows and 4 columns. A mini data > frame is given at the bottom. I want to split the data frame into > lists

Re: [R] Removing a data subset

2017-11-29 Thread Rainer Schuermann
Reading in the data from the file x <- read.csv( "ExampleData.csv", header = TRUE, stringsAsFactors = FALSE ) Subsetting as you want x <- x[ x$Location != "MW01", ] This selects all rows where the value in column 'Location' is not equal to "MW01". The comma after that ensures that

Re: [R] [FORGED] Re: remove

2017-02-12 Thread Rainer Schuermann
I may not be understanding the question well enough but for me df[ df[ , "first"] != "Alex", ] seems to do the job: first week last Rainer On Sonntag, 12. Februar 2017 19:04:19 CET Rolf Turner wrote: > > On 12/02/17 18:36, Bert Gunter wrote: > > Basic stuff! > > > > Either

Re: [R] Problem with X11

2016-04-19 Thread Rainer Schuermann
Probably wrong list, but anyway: Same problem here, after a apt-get dist-upgrade On Tuesday, April 19, 2016 05:23:37 PM Lorenzo Isella wrote: > Dear All, > I have never had this problem before. I run debian testing on my box > and I have recently update my R environment. > Now, see what

Re: [R] Existence of an object

2015-11-06 Thread Rainer Schuermann
Quotation marks help also for exists(): exists( "meanedf" ) [1] TRUE On Saturday 07 November 2015 04:48:04 Margaret Donald wrote: > I have a variable meanedf which may sometimes not be defined due to a > complex set of circumstances. > I would like to be able to find out whether or not it

Re: [R] Existence of an object

2015-11-06 Thread Rainer Schuermann
For me, "meanedf" %in% ls() works: meanedf <- 1 "meanedf" %in% ls() [1] TRUE rm( meanedf ) "meanedf" %in% ls() [1] FALSE Rgds, Rainer On Saturday 07 November 2015 04:48:04 Margaret Donald wrote: > I have a variable meanedf which may sometimes not be defined due to a > complex set of

Re: [R] Removing rows in a data frame

2015-07-03 Thread Rainer Schuermann
Try y - x[ -( 30596:678013 ), ] Please note that I have replaced 30595 with 30596 which is I think what you mean. You can add a new column with y$new - new_column # this is your vector of length 30595 Good luck, Rainer On Friday 03 July 2015 07:23:28 Charles Thuo wrote: I have a data

Re: [R] Correlation matrix for pearson correlation (r,p,BH(FDR))

2015-06-18 Thread Rainer Schuermann
The way the sample data is provided is not useful. I have re-built your data, please find the dput() version below (and pls check whether I got it right...). This is not my area of competence at all, but from what I see from the help page is that the expected parameters are, among others: x

Re: [R] A simple For-Loop doesn't work

2015-03-15 Thread Rainer Schuermann
Hi Nick, Your code is not exactly commented, minimal, self-contained, reproducible and contains a number of inconsistencies (Data has three elements, your loop expects six). Try something like Data - c(July, August, September) ... for( x in Data ) { currentData - read.csv( paste( x,

Re: [R] Installing gWidgetsRGtk2: R session is headless

2014-10-23 Thread Rainer Schuermann
Michael, thanks, that was it! I had installed the packages as root and tried them out as root (not a good idea I know, but I was lazy), while running the the X11 display as user. Worse is that I have done that many times. One more thing learned. Thanks again, Rainer On Thursday 23 October 2014

Re: [R] format negative numbers

2014-10-20 Thread Rainer Schuermann
Maybe not the most elegant way but at least works: library( stringr ) x - as.factor( 123.4- ) x - -as.numeric( str_replace( as.character( x ), -, ) ) x [1] -123.4 On Monday 20 October 2014 09:03:36 PIKAL Petr wrote: Dear all. Before I start fishing in (for me) murky regular expression

Re: [R] Which() missing a number

2014-03-18 Thread Rainer Schuermann
... and it is also missing the 15 at position 15. Can't explain but which( neilist %in% pfriends ) should give you what you want. On Tuesday 18 March 2014 11:14:08 Thomas wrote: Does anyone know why this is happening? Which() is picking up the indices of the numbers 13 and 15 in

Re: [R] question on more efficient data block-match processing

2014-03-07 Thread Rainer Schuermann
What I would do: # read in your sample data mbr - read.table( clipboard, header = TRUE, stringsAsFactors = FALSE ) # create a vector with the codes you want to consider code.list - c(A,B,C,D,E) # reduce the data accordingly mbr - mbr[ mbr$code %in% code.list, ] # get your model matrix using

Re: [R] keep track of variables created in each chapter of a knitr book

2014-01-25 Thread Rainer Schuermann
You could initialize one list per chapter, x1 - list( Chapter One ) and then crate your variables as list members x1$A - c( 1, 2, 3 ) x1$B - bla x1$tv.data - data.frame( m = sample( LETTERS, 5 ), n = round( runif( 5 ), 2 ) ) x1 [[1]] [1] Chapter One $A [1] 1

Re: [R] Generate Variable Length Strings from Various Sources

2014-01-15 Thread Rainer Schuermann
### How I would do it: # container for the result res - NULL # number of strings to be created n - 50 # random length of each string v.length = sample( c( 2:4), n, rep = TRUE ) # letter sources src.1 = LETTERS[ 1:10 ] src.2 = LETTERS[ 11:20 ] src.3 = z src.4 = c( 1, 2 ) # turn into a list src

Re: [R] xtable: custom row.names, move caption to top

2013-11-27 Thread Rainer Schuermann
You get the cation to the top of the table with print( saxtab, caption.placement = top ) Formatting the table the way you want can be done like this - I did not manage to carry the LaTeX math formatting for the row names over ($k$ and $n_k$)but the rest should be very much what you want:

Re: [R] xtable: custom row.names, move caption to top

2013-11-27 Thread Rainer Schuermann
{table} On Wednesday 27 November 2013 17:43:30 Rainer Schuermann wrote: You get the cation to the top of the table with print( saxtab, caption.placement = top ) Formatting the table the way you want can be done like this - I did not manage to carry the LaTeX math formatting for the row

[R] Installing RCurl: 'configure' exists but is not executable

2013-11-01 Thread Rainer Schuermann
I'm trying to install.packages( RCurl ) as root but get ERROR: 'configure' exists but is not executable I remember having had something like that before on another machine and tried in bash what is described here http://mazamascience.com/WorkingWithData/?p=1185 and helped me before: # mkdir

Re: [R] Installing RCurl: 'configure' exists but is not executable

2013-11-01 Thread Rainer Schuermann
, Nov 1, 2013 at 7:43 PM, Rainer Schuermann rainer.schuerm...@gmx.net wrote: I'm trying to install.packages( RCurl ) as root but get ERROR: 'configure' exists but is not executable I remember having had something like that before on another machine and tried in bash what is described here

Re: [R] First time r user

2013-08-18 Thread Rainer Schuermann
It would be helpful if - you give us some sample data: dput( head( myData ) ) - tell us what kind of function you want to apply, or how the result looks like that you want to achieve - show us what you have done so far, and where you are stuck On Saturday 17 August 2013 19:33:08

Re: [R] How to vectorize subsetting

2013-08-14 Thread Rainer Schuermann
I'm sure there are better, more elegant ways avoiding the nested loop I'm suggesting - but if it was my problem, here is what I would do (assuming that my understanding of your question is correct): ### separate function for 'doing something' with the data subset do.something - function( qA, qB

Re: [R] Week number for a given date

2013-08-14 Thread Rainer Schuermann
What about ?lubridate particulatrly week()? On Wednesday 14 August 2013 22:00:42 Christofer Bogaso wrote: Hello again, I need to calculate the week number of the corresponding month given a date. Is there any function available with R to calculate that? Thanks and regards,

Re: [R] Using text and variable in ggtitle (ggplot2)

2013-07-19 Thread Rainer Schuermann
Not sure whether I understand your question fully but I guess paste() is your friend: ggtitle( paste( RR(overall) =, RR, N =, N, alpha =, alpha1 ) ) On Friday 19 July 2013 17:17:24 Manisha Brahma chary wrote: Hello, I am using ggplot2 to plot a graph and I want to give a title to the plot

Re: [R] Serialize data.frame to database

2013-07-16 Thread Rainer Schuermann
Maybe a simple dbWriteTable( db, frames, iris ) does what you want? On Monday 15 July 2013 23:43:18 Simon Zehnder wrote: Dear R-Users, I need a very fast and reliable database solution so I try to serialize a data.frame (to binary data) and to store this data to an SQLite database.

Re: [R] Fetch and merge from a data set

2013-06-25 Thread Rainer Schuermann
Is merge( data[1], data1 ) what you want? On Tuesday 25 June 2013 12:00:23 Nico Met wrote: Many thanks Rui, However If I want to extract only first column (data1) from data file, then how Can I do it? Thanks again Nico On Tue, Jun 25, 2013 at 11:43 AM, Rui Barradas

Re: [R] Creating subset using selected columns

2013-06-16 Thread Rainer Schuermann
Supposed your data.frame is called x, try x[ which( substr( colnames( x ), 1, 4 ) == Peak ) ] On Sunday 16 June 2013 15:20:37 Suparna Mitra wrote: Hello R experts, I need a help to create a subset file. I know with subset comand, its very easy to select many different columns, or threshold.

Re: [R] rename and concatenate name of columns

2013-06-14 Thread Rainer Schuermann
df1 - data.frame( A = runif( 10 ), B = runif( 10 ) * 5, C = runif( 10 ) * 10, D = runif( 10 ) * 20 ) df2 - data.frame( X = runif( 10 ), Y = runif( 10 ) * 5, Z = runif( 10 ) * 10 ) rename_columns - function( dataset ) { for( i in 2:ncol( dataset ) ) colnames( dataset )[i] -

Re: [R] checking certain digits of a number in a column

2013-06-14 Thread Rainer Schuermann
Try ?grep or library( stringr ) ?str_detect On Saturday 15 June 2013 00:33:31 Yasin Gocgun wrote: Hi, I need to check whether certain digits of a number, say, last five digits, appear in a column of a data frame. For instance, For example,103 in 000103 ( data [data[,3] == ...103]

Re: [R] loops for matrices

2013-06-12 Thread Rainer Schuermann
The comments on StackOverflow are fair, I believe... Please dput() your matrices, so that your code becomes reproducible! On Wednesday 12 June 2013 11:14:35 maggy yan wrote: I have to use a loop (while or for) to return the result of hadamard product. now it returns a matrix, but when I use

Re: [R] error in rowSums in data.table

2013-05-30 Thread Rainer Schuermann
On Thursday 30 May 2013 02:57:04 Camilo Mora wrote: do you know why is this? or is there another way to sum by row in a given number of columns? Without data.table: x - structure(list(col1 = c(NA, 0, -0.015038, 0.003817, -0.011407 ), col2 = c(0.003745, 0.007463, -0.007407, -0.003731,

Re: [R] adding rows without loops

2013-05-23 Thread Rainer Schuermann
Using the data generated with your code below, does rbind( DF1, DF2[ !(DF2$X.TIME %in% DF1$X.TIME), ] ) DF1 - DF1[ order( DF1$X.DATE, DF1$X.TIME ), ] do the job? Rgds, Rainer On Thursday 23 May 2013 05:54:26 Adeel - SafeGreenCapital wrote: Thank you Blaser: This is the exact solution I

Re: [R] formatting column names of data frame

2013-05-17 Thread Rainer Schuermann
Have you tried xtable? library( xtable ) x - structure(list(Record = 1:3, Average = c(34L, 14L, 433L), Maximum = c(899L, 15L, 1003L)), .Names = c(Record, Average, Maximum), class = data.frame, row.names = c(NA, -3L)) x - xtable( x ) print( x ) % latex table generated in R 2.15.2 by xtable

Re: [R] Merge two dataframe with by, and problems with the common field

2013-05-07 Thread Rainer Schuermann
Not sure whether this really helps you but at least it works for your sample: d3 - merge( d1, d2, by = c( a, b ) ) d3

Re: [R] Missing data

2013-04-25 Thread Rainer Schuermann
I read your data into a dataframe x - read.table( clipboard ) and renamed the only column colnames( x )[1] - orig With a loop, I created a 2nd column miss where in every 10th row the observation is set to NA: for( i in 1 : length( x$orig ) ) { if( as.integer( rownames( x )[ i ] ) %% 10

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rainer Schuermann
Probably not very R-ish but it works (your data in a dataframe called x), if I understand your question right: # replace NA with 0 x$mth - ifelse( is.na( x$mth ), 0, x$mth ) # loop through observation numbers and replace 0 with the month no for( i in unique( x$obs ) ) x$mth[ x$obs == i ] - max(

Re: [R] Can R read open office.org Calc files

2013-03-28 Thread Rainer Schuermann
This might help: http://www.omegahat.org/ROpenOffice/ Rgds, Rainer On Thursday 28 March 2013 17:32:23 Shane Carey wrote: Hi, Can R read open office.org Calc files Thanks __ R-help@r-project.org mailing list

Re: [R] Combinations

2013-03-15 Thread Rainer Schuermann
Is ?expand.grid what you are looking for? Rgds, Rainer On Friday 15 March 2013 09:22:15 Amir wrote: Hi every one, I have two sets T1={c1,c2,..,cn} and T2={k1,k2,...,kn}. How can I find the sets as follow: (c1,k1), (c1,k2) ...(c1,kn) (c2,k1) (c2,k2) (c2,kn) ... (cn,kn)

Re: [R] How can I read the following complicated table

2012-12-13 Thread Rainer Schuermann
What have you tried so far that did not work, and what do you want the result of your reading the text file look like? What is store somewhere? Why does myDF - read.table( myData.txt ) which gives you myDF V1 V2 V3 V4 1Monday 12 78 89 2 Tuesday 34 44 67 3 Wednesday 78 98 2

Re: [R] help with if statement

2012-11-21 Thread Rainer Schuermann
Does A$TIME - ifelse( A$TIME = 24, A$TIME + 24, A$TIME ) what you want? Rgds, Rainer On Wednesday 21 November 2012 09:05:39 york8866 wrote: Hi all, I had a dataset A like: TIME DV 0 0 1 10 520 24 30 36 80 48 60 72 15 I would like to add 24 to those values higher

Re: [R] Scaling values 0-255 - -1 , 1 - how can this be done?

2012-11-21 Thread Rainer Schuermann
x - as.data.frame( matrix( 0:255, nrow = 16 ) ) ifelse( x 127.5, 1, -1 ) Is that what you want? Rgds, Rainer On Wednesday 21 November 2012 10:32:49 Brian Feeny wrote: I have a dataframe in which I have values 0-255, I wish to transpose them such that: if value 127.5 value = 1 if

Re: [R] Using cbind to combine data frames and preserve header/names

2012-11-16 Thread Rainer Schuermann
Not sure where the problem is? Since you did not provide sample data, I took the iris data set and converted it to your structure: x - cbind( iris[5], iris[1:3] ) head( x ) Species Sepal.Length Sepal.Width Petal.Length 1 setosa 5.1 3.5 1.4 2 setosa 4.9

Re: [R] summation coding

2012-10-19 Thread Rainer Schuermann
Assuming that you actually mean a1(b2+b3+b4) + a2(b1+b3+b4) + a3(b1+b2+b4) + a4(b1+b2+b3) ^ ^ ^ this might give you what you want: x - data.frame( a = sample( 1:10, 4 ), b = sample( 11:20, 4 ) ) x

Re: [R] summation coding

2012-10-19 Thread Rainer Schuermann
the following: a1(b2+...+b190) + a2(b1+b3+...+b190) + ... I managed to solve it, quite similar to what you just emailed. Thanks! On 19 October 2012 09:20, Rainer Schuermann rainer.schuerm...@gmx.netwrote: Is it possible that you mean a1(b2+b3+b4) + a2(b1+b3+b4) + a3(b1+b2+b4) + a4(b1+b2+b3

Re: [R] unique

2012-10-16 Thread Rainer Schuermann
If I understand your problem correctly (as Milan has pointed out, sample data and code would help enormously) this should get you where you want: unique( shopdata$name[ shopdata$employee 10 ] ) If not, something is wrong from the outset (or with my understanding, but then ... see above)!

Re: [R] How to Rename Column Labels?

2012-09-08 Thread Rainer Schuermann
You can't do that on disk - try: dfr - read.table ( /Users/MAC/Desktop/data.txt ) dfr A1 A2 A3 A4 A5

Re: [R] Help on finding specific columns in matrix

2012-09-02 Thread Rainer Schuermann
If I understand your question correctly, you want to identify the one column that has the lowest mean of all columns, and the one column that has the highest mean of all columns. Using your provided sample data, this gives you the indices: colMeans(a) [1] 12.48160 17.46868 22.51761 27.59880

Re: [R] Finding the last value before a certain date

2012-07-19 Thread Rainer Schuermann
dat - structure(list(date = structure(c(14879, 14886, 14893, 14899, 14906, 14913), class = Date), y = c(1356L, 1968L, 2602L, 3116L, 3496L, 3958L)), .Names = c(date, y), row.names = c(1, 2, 3, 4, 5, 6), class = data.frame) x - as.Date( 2010-10-06 ) getY - function( x ) { dat[ dat$date = x, 2][

Re: [R] Truncating (rounding down) to nearest half hour.

2012-07-19 Thread Rainer Schuermann
My amateur approach: I put your data in a dataframe called t: head( t ) Date Score 1 2008-05-01 08:58:0080 2 2008-05-01 13:31:0011 3 2008-05-01 16:35:0081 4 2008-05-01 23:20:00 152 5 2008-05-02 01:01:00 130 6 2008-05-02 03:35:00 122 Then I created a vector

Re: [R] Last answer

2012-07-19 Thread Rainer Schuermann
Is that what you mean: 2 + 3 [1] 5 .Last.value [1] 5 Rgds, Rainer (from R-intro.pdf, page 7, 2nd footnote) Original-Nachricht Datum: Thu, 19 Jul 2012 22:12:22 -0700 (PDT) Von: darnold dwarnol...@suddenlink.net An: r-help@r-project.org Betreff: [R] Last answer Hi,

Re: [R] please help! Extract the row to the new file by using if-statment

2012-05-31 Thread Rainer Schuermann
Not sure whether I understand your data and objectives well enough but here is what I would do: To make my life easier, I used x as a variable name. I'm not using attach(). You can extract your data with something like y - x[x$wrfta= 255 | x$wrfta= 65 x$wrfrain == 0, ] y - y[!is.na(y[5]),] y

Re: [R] storing output of a loop in a matrix

2012-05-23 Thread Rainer Schuermann
Try for( i in 1:10 ){ ... } That should resove your problem 1.! Rgds, Rainer On Wednesday 23 May 2012 09:23:04 RH Gibson wrote: blap.txt is a numeric vector of length 64. I am using the following code: bd-scan(blap.txt) output-matrix(0,64,10) s-sum(bd) for (i in 10){ while

Re: [R] What's wrong with MEAN?

2012-05-22 Thread Rainer Schuermann
mean( 16, 18 ) [1] 16 mean( c( 16, 18 ) ) [1] 17 On Tuesday 22 May 2012 02:10:27 Vincy Pyne wrote: Dear R helpers, I have recently installed R version 2.15.0 I just wanted to calculate mean(16, 18) Surprisingly I got answer as mean(16, 18) [1] 16 mean(18, 16)

Re: [R] how to do averaging of two tables (rows with columns)

2012-05-11 Thread Rainer Schuermann
Based upon my understanding of your problem, this should do the job: d3 - dat1 d3[2] - ifelse( d3[2] == 1, dat2[1,2], NA ) d3[3] - ifelse( d3[3] == 1, dat2[2,2], NA ) d3[4] - Nodata d3[5] - ifelse( d3[5] == 1, dat2[3,2], NA ) d3$average - rowMeans( d3[c(2,3,5)], na.rm = TRUE ) d3 is now

Re: [R] [Sweave] string.prefix without hyphen-minus

2012-05-04 Thread Rainer Schuermann
You cannot avoid the hyphen I think, but if you say (for example): prefix.string=foo/x then your files start with 'x-' (so 'graph' becomes 'foo/x-graph') which may be better for you than the hyphen at the beginning of the file name. Rgds, Rainer On Friday 04 May 2012 17:23:58

Re: [R] Sweave: Avoiding recompilation of figures

2012-04-26 Thread Rainer Schuermann
The easiest way probably is to put the code that takes so long to execute, in a separate file, such as graph1.Rnw, and get it into your master file via SweaveInput( graph1.Rnw ). Once you are happy with your graph1, you can comment this line out and only compile the stuff that keeps changing.

Re: [R] How to reduce plot size on linux?

2012-04-25 Thread Rainer Schuermann
Cross posting http://stackoverflow.com/questions/10308955/how-to-reduce-image-size-in-sweave The code you have provided there is unusable, I assume your problems come from a lack of understanding how Sweave works (nothing to do with Linux). Always make sure that = and @ are always the first

Re: [R] recommended way to group function calls in Sweave

2012-04-25 Thread Rainer Schuermann
What I usually do when I have to write a report with some functions I use multiple times is that I put them in a separate file (call it setup.Rnw or so). The first chunk there loads the libraries, sets initial variable values etc: echo=FALSE, results=hide= library( xtable ) d - iris ind - 1 @

Re: [R] Encoding of Sweave file error message

2012-04-12 Thread Rainer Schuermann
I also had the same problem. Being on Linux, I prefer Walmes' command line method but I found that putting \usepackage[utf8x]{inputenc} as the first instruction in the master .Rnw file also does the trick. No need to change anything after that in the file, at least not for me! Rgds, Rainer On

Re: [R] Recode Variable

2012-04-12 Thread Rainer Schuermann
1. Some data structured the way you are using would have been helpful. I used Tal Galil's play data and set up a dataframe with the variable names you are using: structure(list(var1 = c(1, NA, NA, 4, 5, 6, 7, 8, 9, 10, 5), var2 = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5)), .Names = c(var1, var2),

Re: [R] cbind, data.frame | numeric to string?

2012-04-10 Thread Rainer Schuermann
cbind() works as well, but only if c is attached to the existing test variable: tst - cbind( test, c ) tst ab c

Re: [R] How to convert factors to numbers

2012-03-24 Thread Rainer Schuermann
I guess the problem starts with setting read.table(...dec = ,, ... ). The data in your file are with decimal point. Without that, it works just fine: f - http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt; df - read.table( f, header = TRUE ) log.Price - log(df$price) head(

Re: [R] R (Bold font) and Latex

2012-03-23 Thread Rainer Schuermann
More information (reproducible code) is needed to address your specific situation, but in general, you change the value of a variable in R and take care of the formatting in LaTeX. You may want to look at the Hmisc package's Latex() function. I have not tried it, xtable serves me well, but

Re: [R] How to change colnames in xtable?

2012-03-22 Thread Rainer Schuermann
You can change the column names of a data frame with colnames( df ) - c( my, data, frame ) and from here, xtable() is your friend (or at least mine...). Rgds, Rainer On Thursday 22 March 2012 01:13:18 Manish Gupta wrote: Hi, Can we change column names in latex table? Regards --

Re: [R] R (Bold font) and Latex

2012-03-20 Thread Rainer Schuermann
For a small number of elements you could use \Sexpr{}, i.e. echo= FALSE= x-c(1,0,2,4) @ x\\ \textbf{\Sexpr{x[1]}}\\ \textbf{\Sexpr{x[2]}}\\ \textbf{\Sexpr{x[3]}}\\ \textbf{\Sexpr{x[4]}}\\ Rgds, Rainer On Monday 19 March 2012 20:03:47 Manish Gupta wrote: Hi, I am using R and latex for

Re: [R] R (Bold font) and Latex

2012-03-20 Thread Rainer Schuermann
Or, with a little less typing: echo= FALSE= x-c(1,0,2,4) @ x\\ \begin{textbf} \Sexpr{x[1]}\\ \Sexpr{x[2]}\\ \Sexpr{x[3]}\\ \Sexpr{x[4]}\\ \end{textbf} On Tuesday 20 March 2012 10:14:38 Rainer Schuermann wrote: For a small number of elements you could use \Sexpr{}, i.e. echo= FALSE= x-c

Re: [R] a very simple question

2012-03-19 Thread Rainer Schuermann
As to the reasons, David as given you the necessary hints. In order to get around the issue, here is what I do: a - round( 0.1 * ( 1:9 ), 1 ) a [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 which( a == 0.3 ) [1] 3 Rgds, Rainer Original-Nachricht Datum: Sun, 18 Mar 2012

Re: [R] How to retrieve a column name of a data frame

2012-02-02 Thread Rainer Schuermann
colnames( df )[2] [1] c2 On Thursday 02 February 2012 07:31:33 ikuzar wrote: Hi, I 'd like to know how to retrieve a column name of a data frame. For instance : df = data.frame(c1=c('a','b'),c2=c(1,2)) df c1 c2 1 a 1 2 b 2 I would like to retrieve the column name

Re: [R] function: as.integer

2012-01-31 Thread Rainer Schuermann
as.numeric(A) [1] 4.4 1.9 4.1 Integers are just integers... On Tuesday 31 January 2012 12:21:48 Marion Wenty wrote: dear r-helpers, i created an object named A, which looks like this: A - c(4.4,1.9,4.1) now i needed to get numbers instead of characters and for this i used the

Re: [R] reshape dataframe to array (pivot table)

2012-01-24 Thread Rainer Schuermann
Hi, I wouldn't know how to fill the data into the array form you want, but you can get the aggregated data with dfm - melt( df ) dfc - cast( dfm, LOC ~ variable, sum ) dfc LOC SPEC1 SPEC2 1 123 5 2 223 2 3 3 0 0 Hope this helps as a first step! Rgds, Rainer

Re: [R] Using Sweave to generate multiple documents

2012-01-16 Thread Rainer Schuermann
Coming from a different angle: The LaTeX beamer class comes with the capability to produce different sets of documents from the same master file (presentation, handout, article...). That could get you where you want. For sweave questions, you may want to look at

Re: [R] nice report generator?

2011-12-07 Thread Rainer Schuermann
... or perhaps some other CRAN package has already gone in this direction. The tableGrob function in the gridExtra package probably is one of them. Original-Nachricht Datum: Wed, 7 Dec 2011 19:29:54 -0500 Von: Gabor Grothendieck ggrothendi...@gmail.com An: Duncan Murdoch

Re: [R] bizarre seq() behavior?

2011-11-23 Thread Rainer Schuermann
You have a dot (not a comma) after 8: seq(2,8.1,length.out=3) ^ Rgds, Rainer On Wednesday 23 November 2011 06:59:12 Czerminski, Ryszard wrote: Is there any rational explanation for the bizarre seq() behavior below? seq(2,8.1, lenght.out=3) [1] 2 3 4 5 6 7 8 help(seq)

Re: [R] bizarre seq() behavior?

2011-11-23 Thread Rainer Schuermann
...and a spelling mistake in your first line (lenght instead of length)... On Wednesday 23 November 2011 06:59:12 Czerminski, Ryszard wrote: Is there any rational explanation for the bizarre seq() behavior below? seq(2,8.1, lenght.out=3) [1] 2 3 4 5 6 7 8 help(seq)

Re: [R] problem in creating a dataframe

2011-11-22 Thread Rainer Schuermann
Being new to R myself, I always get trapped by factors. Taking the data you have provided, this worked for my understanding of your intention: x - rep( 0, 4 ) x [1] 0 0 0 0 df - data.frame( matrix( x, 1 ), stringsAsFactors = FALSE ) df X1 X2 X3 X4 1 0 0 0 0 is.character( df[1,1] ) [1]

Re: [R] Generating Sequence of Dates

2011-11-20 Thread Rainer Schuermann
n = 2 sort( rep( seq(as.Date(2000/1/1), by=month, length.out=3), n ) )

Re: [R] xtable and sweave: caption placement problem

2011-11-18 Thread Rainer Schuermann
It works if you separate the print command and put the caption placement in the print command , see below: \documentclass[11pt,a4paper]{article} \usepackage{Sweave} \begin{document} = x = runif(100, 1, 10) y = 2 + 3 * x + rnorm(100) @ echo=FALSE,results=tex= library(xtable) p -

Re: [R] length of empty string

2011-11-18 Thread Rainer Schuermann
nchar() [1] 0 On Friday 18 November 2011 16:09:38 Jaensch, Steffen [TIBBE] wrote: Hi all, Can somebody

Re: [R] regular expression for selection

2011-11-14 Thread Rainer Schuermann
Does library( stringr ) str_extract( mena, m5[0-9] ) achieve what you are looking for? Rgds, Rainer On Monday 14 November 2011 10:22:09 Petr PIKAL wrote: Hi On 11/14/2011 07:45 PM, Petr PIKAL wrote: Dear all I am again (as usual) lost in regular expression use for selection.

Re: [R] Extracting data by row

2011-10-29 Thread Rainer Schuermann
On Friday 28 October 2011 18:04:59 Vinny Moriarty wrote: Thanks everyone for you help with my last question, and now I have one last one... Here is what I would do, based on my understanding of your question: # your data snippet as data frame x site time_localtime_utc

Re: [R] converting commas to points

2011-10-06 Thread Rainer Schuermann
From ?read.csv: read.csv2( file, header = TRUE, sep = ;, quote=\, dec=,, fill = TRUE, comment.char=, ...) I think this is specifically set up for German decimal commas. Rgds, Rainer On Thursday 06 October 2011 17:39:46 Anna Lee wrote: Hello everyone! I work with a german excell

Re: [R] Populate a matrix

2011-10-05 Thread Rainer Schuermann
m - matrix( rep( y, length( x ) ), length( y ), length( x ) ) On Wednesday 05 October 2011 18:11:18 fernando.cabr...@nordea.com wrote: Hi guys I have vectors x - c(1,2,3,4) and y - c(4,3,9) and would like to generate a matrix which has 3 rows (length(y)) and 4 columns (length(x)), and

Re: [R] Efficient way to do a merge in R

2011-10-04 Thread Rainer Schuermann
Any comments are very welcome, So I give it a shot, although I don't have answers but only some ideas which avenues I would explore, not being an expert at all: 1. I would try to be more restrictive with the columns used for merge, trying something like m1 - merge( x, y, by.x = V1, by.y = V1,

Re: [R] download files using ftp: avoid error

2011-09-16 Thread Rainer Schuermann
I haven't tested it thoroughly but what worked here is replacing download.file(url, destfile, quiet = FALSE) with sys_call - paste( wget, url, , destfile, sep= ) system( sys_call ) Program execution continues, whether or not the download from url was successful. However, wget is, I believe,

Re: [R] Reading large, non-tabular files

2011-09-14 Thread Rainer Schuermann
That looks like a perfect job for (g)awk which is in every Linux distribution but also available for Windows. It can be called with something like system( awk -f script.awk inputfile.txt ) and does its job silently and very fast. 650MB should not be an issue. I'm not proficient in awk but

Re: [R] Subset function

2011-09-09 Thread Rainer Schuermann
Does that help: x xin xout 1 1 14 2 85 3 16 884 4 1 14 5 85 6 16 884 subset( x, x$xin 7, select = xout )

Re: [R] Asking Favor For Remove element with Particular Value In Vector

2011-08-27 Thread Rainer Schuermann
Not sure whether I understand your question right but here is what I would do: # Sample data x - seq( 1, 100, by=6) x [1] 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 # remove element with value 19 x - x[ x != 19 ] x [1] 1 7 13 25 31 37 43 49 55 61 67 73 79 85 91 97 If you want to

Re: [R] To import data to R from Excel

2011-08-11 Thread Rainer Schuermann
In Excel, make sure that your data has a format that corresponds to an R data frame (first row with column names, consistent column size and data type). Export your .XLS worksheet as .CSV file (mydata.csv). In R, read it into a data frame with read.csv( mydata.csv ) From here, you shold be

Re: [R] Getting Started

2011-07-21 Thread Rainer Schuermann
cran.r-project.org/doc/manuals/R-intro.pdf cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf cran.r-project.org/doc/contrib/Verzani-SimpleR.pdf cran.r-project.org/doc/contrib/Lemon-kickstart/kr_intro.html https://stat.ethz.ch/mailman/listinfo/r-help On Thursday 21 July 2011 10:46:43 Varsha

Re: [R] for/if loop in R

2011-07-21 Thread Rainer Schuermann
For me, this works: Now, I want to add a 4th column, trend pricedata$trend - 0 which can have 2 values 0 or 1. if return1%, trend=1 else trend=0. pricedata$trend - ifelse( pricedata$return .01, 1, 0 ) Rgds, Rainer On Thursday 21 July 2011 19:39:15 financial engineer wrote: hi, Can

Re: [R] read.csv help

2011-07-19 Thread Rainer Schuermann
Can you explain a little more? I have created a small CSV file following your pattern which looks like this in a text editor: A,B,C,D,E 65,68,71,74,77 67,71,75,79,83 69,73,77,81,85 71,77,83,89,95 When I load it into R with x - read.csv( a.csv ) I get this which I think is what you would

Re: [R] as.numeric

2011-07-12 Thread Rainer Schuermann
It may be helpful to make sure that, in the dialog that pops up when saving a spreadsheet to CSV, the option Save cell content as shown is checked - that would leave numbers as numbers, not wrapping them in . That has helped me at least in a similar situation! Rgds, Rainer On Tuesday 12 July

Re: [R] How many times occurs

2011-07-03 Thread Rainer Schuermann
On Saturday 02 July 2011 21:40:24 Trying To learn again wrote: Clumsy but it works (replace the bingo stuff with what you want to do next): x - as.matrix( read.table( input.txt) ) xdim - dim( x ) ix - xdim[ 1 ] jx - xdim[ 2 ] - 2 bingo - 0 for( i in 1:ix ) { for( j in 1:jx ) { if(

Re: [R] How many times occurs

2011-07-03 Thread Rainer Schuermann
Sorry, I forgot to attach the original post, so here once more with a cosmetic change: x - as.matrix( read.table( matr.txt) ) bingo - 0 for( i in 1:dim( x )[1] ) { for( j in 1:dim( x )[2] - 2 ) { if( x[i,j] == 8 x[i,j+1] == 9 x[i,j+2] == 2 ) { bingo - bingo + 1 } } }

Re: [R] How to export to pdf in landscape orientation?

2011-06-25 Thread Rainer Schuermann
Tell PDF the size of your piece of paper - here is what works for me: pdf( file = result.pdf, width = 28, height = 18 ) # numbers are cm some( stuff ) dev.off() Hope it helps, Rainer On Saturday 25 June 2011 18:46:28 Juan Andres Hernandez wrote: Does anybody know how to get a pdf

Re: [R] Unable to require installed package

2011-01-27 Thread Rainer Schuermann
On Thursday, January 27, 2011 08:57:01 am 刘力平 wrote: who sincerely thinks R is not google friendly, since R is a awful keyword. http://www.rseek.org/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

Re: [R] Find the sign

2011-01-24 Thread Rainer Schuermann
On Monday, January 24, 2011 07:18:03 pm Alaios wrote: Hello :) I wanted to right an expression to check when x and y have the same sign and I wrote the following: if ((x0 y0) || (x0 y0)) which looks pretty ugly to me. Can you please suggest me a better way for that? Regards

Re: [R] Normal Distribution Quantiles

2011-01-09 Thread Rainer Schuermann
Altogether I got five more or less silly solutions (not my judgment!), some of them further discussed in private mail, for a problem where my expectation was to get a simple one-liner back: Check ?clt or so... Fortunately, with all of them I seem to arrive at a result that is consistent with

[R] Normal Distribution Quantiles

2011-01-08 Thread Rainer Schuermann
This is probably embarrassingly basic, but I have spent quite a few hours in Google and RSeek without getting a clue - probably I'm asking the wrong questions... There is this guy who has decided to walk through Australia, a total distance of 4000 km. His daily portion (mean) is 40km with an

Re: [R] Normal Distribution Quantiles

2011-01-08 Thread Rainer Schuermann
^-)) 2 On Saturday 08 January 2011 14:56:20 you wrote: On Jan 8, 2011, at 6:56 AM, Rainer Schuermann wrote: This is probably embarrassingly basic, but I have spent quite a few hours in Google and RSeek without getting a clue - probably I'm asking the wrong

Re: [R] Numbers in a string

2010-12-15 Thread Rainer Schuermann
If your OS is Linux, you might want to look at sed or gawk. They are very good and efficient for such tasks. You need it once or as a part of program? Some samples would be helpful... Rgds, Rainer Original-Nachricht Datum: Wed, 15 Dec 2010 16:55:26 +0800 Von: Luis Felipe

  1   2   >