Re: [R] Remove all factor levels from an R dataframe

2020-11-10 Thread Eric Berger
Hi John, I was thinking that you created df1 in a way that set the 'year' column as a factor when this is not what you wanted to do. The data.frame() function takes an argument stringsAsFactors which controls this behavior. For R versions 3.6.3 or earlier, the default setting is stringsAsFactors=TR

Re: [R] Remove all factor levels from an R dataframe

2020-11-10 Thread Jim Lemon
Sure John, df1<-df1[order(as.character(df1$year),decreasing=TRUE),] Jim On Tue, Nov 10, 2020 at 8:05 PM John wrote: > Thanks Jim. Can we do descending order? > > Jim Lemon 於 2020年11月10日 週二 下午4:56寫道: > >> Hi John, >> >> df1<-sapply(df1,as.character) >> >> Should do what you ask. The error mess

Re: [R] Remove all factor levels from an R dataframe

2020-11-10 Thread John
Thanks Jim. Can we do descending order? Jim Lemon 於 2020年11月10日 週二 下午4:56寫道: > Hi John, > > df1<-sapply(df1,as.character) > > Should do what you ask. The error message probably means that you should > do this: > > df1<-df1[order(as.character(df1$year)),] > > as "year" is the name of the first co

Re: [R] Remove all factor levels from an R dataframe

2020-11-10 Thread Jim Lemon
Hi John, df1<-sapply(df1,as.character) Should do what you ask. The error message probably means that you should do this: df1<-df1[order(as.character(df1$year)),] as "year" is the name of the first column in df1, not a separate object. Jim On Tue, Nov 10, 2020 at 6:57 PM John wrote: > Hi, >

[R] Remove all factor levels from an R dataframe

2020-11-09 Thread John
Hi, I would like to sort the following simple dataframe by "year" (characters), but the factor structure prevents me from doing so. How can I remove the factor structure? Thanks! > df1 year country 4 2007 Asia; survey 5 2010 8 countries in E/SE Asia 6 2015

Re: [R] Dataframe with different lengths

2020-07-29 Thread Ulrik Stervbo via R-help
Hi Pedro, I see you use dplyr and ggplot2. Are you looking for something like this: ``` library(ggplot2) library(dplyr) test_data <- data.frame( year = c(rep("2018", 10), rep("2019", 8), rep("2020", 6)), value = sample(c(1:100), 24) ) test_data <- test_data %>% group_by(year) %>% mut

[R] Dataframe with different lengths

2020-07-22 Thread Pedro páramo
Hi all, I am trying to draw a plot with cumsum values but each "line" has different lengths Ilibrary(dplyr) library(tibble) library(lubridate) library(PerformanceAnalytics) library(quantmod) library(ggplot2) getSymbols('TSLA') I want to create the variables: a<-cumsum(dailyReturn(TSLA, subset

Re: [R] Dataframe by Serial ID

2020-01-08 Thread Eric Berger
Hi Thomas, Jeff is correct that this can be handled via merge, e.g. df3 <- merge( df2, df1, by="Serial", all=FALSE ) This operation is called an "inner join", and you could use other tools, such as the dplyr package to accomplish the same thing df3 <- dplyr::inner_join( df2, df1, by="Serial" ) H

Re: [R] Dataframe by Serial ID

2020-01-08 Thread David Winsemius
> On Jan 8, 2020, at 6:52 AM, Thomas Subia wrote: > > Colleagues, > > I have two data frames which look like this. > > Data frame 1 > > Serial Pre.HolePre.flowPre.Date > 1 30361 0.2419-Nov-19 > 2 30362

Re: [R] Dataframe by Serial ID

2020-01-08 Thread Jeff Newmiller
"merge" is generally the base R answer to this question, and there are equivalent functions in various contributed packages. However, it is necessary to identify which columns in each table uniquely identify each row ("primary key"). If your Serial 3036 shows up 10 times in the first table and

[R] Dataframe by Serial ID

2020-01-08 Thread Thomas Subia
Colleagues, I have two data frames which look like this. Data frame 1 Serial Pre.HolePre.flowPre.Date 1 30361 0.2419-Nov-19 2 30362 0.212 19-Nov-19 3 30363

Re: [R] Dataframe columns are accessible by incomplete column names, is this a bug?

2019-07-18 Thread Patrick (Malone Quantitative)
But it's also a convenience feature. Note that $E returned null because there was an ambiguity. By the time you got to $Ex the column you were referencing was unambiguous and you didn't have to type out the whole thing. Useful if you have very long column names, for example imported from a spreadsh

Re: [R] Dataframe columns are accessible by incomplete column names, is this a bug?

2019-07-18 Thread Sarah Goslee
Hello Yannick, That behavior is documented in the help for subsetting ( ?'$' ): Both ‘[[’ and ‘$’ select a single element of the list. The main difference is that ‘$’ does not allow computed indices, whereas ‘[[’ does. ‘x$name’ is equivalent to ‘x[["name", exact = FALSE]]’.

[R] Dataframe columns are accessible by incomplete column names, is this a bug?

2019-07-18 Thread Yannick.Suter
Hello all I noticed today that you can access dataframe columns by using incomplete names. This is a really unexpected behavior which led to some unexpected errors and I was wondering whether it's a bug or not and whether it should be changed in the future. Here's a working example using the pre

[R] Dataframe Subsetting comparison

2018-03-11 Thread Neha Aggarwal
, while there are certain cols to each U denoted as 1s in each URow in dataframe2. I have to find relationships between Rs and Us. So i start with each U row in U dataframe (lets say U1 row) and try to find all the rows in R dataframe, which are subset of U1 row. I cant find a way to compare rows to

Re: [R] Dataframe is character

2017-11-17 Thread Ivan Calandra
Good one, did not even notice that...! -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, Germany +49 (0) 2631 9772-243 https://www.researchgate.net/pr

Re: [R] Dataframe is character

2017-11-17 Thread Petra Oleum
class("dat") is different from class(dat), which is what you actually want. On 17-11-17, P. Roberto Bakker wrote: > Hi everybody, > > Question: why are my dataframe and numeric variables a character? > > I read an excel file via readxl but my dataframe is a character, and > numeric variables, eg

Re: [R] Dataframe is character

2017-11-17 Thread Ivan Calandra
Hi Roberto, This often happens when there are some non-numeric characters. You would have to check it. Without more information, e.g. dput(dat), you will have to find by yourself. HTH, Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeologic

[R] Dataframe is character

2017-11-17 Thread P. Roberto Bakker
Hi everybody, Question: why are my dataframe and numeric variables a character? I read an excel file via readxl but my dataframe is a character, and numeric variables, eg "yi", are also a character. My excelfile is in English numeric Sometimes the dataframe was indeed a dataframe, but I do not kn

Re: [R] Dataframe Manipulation

2017-09-05 Thread Ulrik Stervbo
rrected these things by hand in the example data. >>>>> >>>>> HTH >>>>> Ulrik >>>>> >>>>> On Wed, 30 Aug 2017 at 10:16 Hemant Sain >>>>> wrote: >>>>> >>>>>> Hey PIKAL, >&

Re: [R] Dataframe Manipulation

2017-09-04 Thread Hemant Sain
;>>>> my company so that i can share the original data file, Actually I'm >>>>> working >>>>> on a market basket analysis task but not able to convert my existing >>>>> data >>>>> table to appropriate format so that i can apply Apriori

Re: [R] Dataframe Manipulation

2017-08-31 Thread Ulrik Stervbo
; R, >>>> and this is very important me to get it done because I'm an intern and >>>> if i >>>> won't get it done they will not going to hire me as a full-time >>>> employee. >>>> i tried everything by myself but not able to

Re: [R] Dataframe Manipulation

2017-08-30 Thread Hemant Sain
ave mentioned . >>> >>> Thanks >>> >>> On 30 August 2017 at 12:49, PIKAL Petr wrote: >>> >>> > Hi >>> > >>> > It seems to me like homework, there is no homework policy on this help >>> > list. >>> &g

Re: [R] Dataframe Manipulation

2017-08-30 Thread Ulrik Stervbo
uger does not match sugar (I wonder that sugar is dairy product) > > > > and you mix uppercase and lowercase letters which could be also > > problematic, when matching words. > > > > Cheers > > Petr > > > > > -Original Message- > > > Fro

Re: [R] Dataframe Manipulation

2017-08-30 Thread Hemant Sain
; and you mix uppercase and lowercase letters which could be also > problematic, when matching words. > > Cheers > Petr > > > -Original Message- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Hemant > Sain > > Sent: Wednesday, August

Re: [R] Dataframe Manipulation

2017-08-30 Thread PIKAL Petr
> Sent: Wednesday, August 30, 2017 8:28 AM > To: r-help@r-project.org > Subject: [R] Dataframe Manipulation > > i want to do a market basket analysis and I’m trying to create a dataset for > that > i have two tables, one table contains daily transaction of products in which >

[R] Dataframe Manipulation

2017-08-30 Thread Hemant Sain
i want to do a market basket analysis and I’m trying to create a dataset for that i have two tables, one table contains daily transaction of products in which each row of table shows item purchased by the customer, The second table contains parent group under those products are fallen, for example

Re: [R] dataframe columns class

2016-12-18 Thread Jeff Newmiller
The apply function operates on arrays, so your data frame is being converted to an array (matrix) before doing its thing. So use lapply or one of its variants. -- Sent from my phone. Please excuse my brevity. On December 18, 2016 9:07:52 AM PST, "Cleber N.Borges via R-help" wrote: >Why colu

Re: [R] dataframe columns class

2016-12-18 Thread Ista Zahn
Read ?apply and you shall be be enlightened. --Ista On Dec 18, 2016 12:09 PM, "Cleber N.Borges via R-help" wrote: > Why columns classes are function dependents? > Like this example: > > > for( i in 1:5 ) print( class( iris[,i] ) ) > [1] "numeric" > [1] "numeric" > [1] "numeric" > [1] "numeric"

[R] dataframe columns class

2016-12-18 Thread Cleber N.Borges via R-help
Why columns classes are function dependents? Like this example: > for( i in 1:5 ) print( class( iris[,i] ) ) [1] "numeric" [1] "numeric" [1] "numeric" [1] "numeric" [1] "factor" > > apply( iris, 2, class ) Sepal.Length Sepal.Width Petal.Length Petal.Width Species "character" "character" "cha

Re: [R] dataframe rbind

2015-12-04 Thread Troels Ring
(10),ID=i)) instead. Cheers Petr -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Troels Ring Sent: Friday, December 04, 2015 5:03 PM To: r-help@r-project.org Subject: [R] dataframe rbind Dear friends - I have a very simple question - I generate a num

Re: [R] dataframe rbind

2015-12-04 Thread peter dalgaard
On 04 Dec 2015, at 17:03 , Troels Ring wrote: > Dear friends - I have a very simple question - > I generate a number of dataframes with identical names and want to combine > them into one large dataframe with the same names - > here is an example > > DF <- data.frame(a=rnorm(10),b=runif(10),ID

Re: [R] dataframe rbind

2015-12-04 Thread Bert Gunter
Try reading and following the Help file, ?rbind.data.frame. You are inventing your own syntax, not using R's. Incidentally, growing the frames as you do is generally a bad idea. Search r-help archives for why. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And

Re: [R] dataframe rbind

2015-12-04 Thread David L Carlson
rom: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Troels Ring Sent: Friday, December 4, 2015 10:03 AM To: r-help@r-project.org Subject: [R] dataframe rbind Dear friends - I have a very simple question - I generate a number of dataframes with identical names and want to combine them int

Re: [R] dataframe rbind

2015-12-04 Thread PIKAL Petr
boun...@r-project.org] On Behalf Of Troels > Ring > Sent: Friday, December 04, 2015 5:03 PM > To: r-help@r-project.org > Subject: [R] dataframe rbind > > Dear friends - I have a very simple question - I generate a number of > dataframes with identical names and want to combine t

[R] dataframe rbind

2015-12-04 Thread Troels Ring
Dear friends - I have a very simple question - I generate a number of dataframes with identical names and want to combine them into one large dataframe with the same names - here is an example DF <- data.frame(a=rnorm(10),b=runif(10),ID=0) for (i in 1:10){ DF <- DF+rbind(data.frame(a=rnorm(10),

[R] dataframe for netcdf data

2015-07-30 Thread prabir das
I am trying to analyse time-series .netcdf (3D lat,long and time domain) climate data. I want to apply the SPEI package (calculation of standardized precipitation evapotranspiration index) on it. But unable to arrange my data in the required data frame. As I am a beginner in R, it will be very much

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-30 Thread PIKAL Petr
Hi Please do not use html formating in your post. It does not bring any advantage. See inline. From: Verena Weinbir [mailto:vwein...@gmail.com] Sent: Thursday, May 29, 2014 3:33 PM To: PIKAL Petr Subject: Re: [R] Dataframe: Average cells of two rows and replace them with one row Hey, Thank you

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-29 Thread PIKAL Petr
-help Subject: Re: [R] Dataframe: Average cells of two rows and replace them with one row Hello, thank you for your reply. Actually, the whole rows would have to be averaged anyways - my mistake :-) Besides the first column "name" there is one other string (chr) variable "Test&q

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-29 Thread Verena Weinbir
nal Message- > > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > > project.org] On Behalf Of Verena Weinbir > > Sent: Wednesday, May 28, 2014 2:00 PM > > To: arun > > Cc: r-help > > Subject: Re: [R] Dataframe: Average cells of two rows and repl

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-28 Thread PIKAL Petr
41. Show us at least structure of your data frame. ?str Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Verena Weinbir > Sent: Wednesday, May 28, 2014 2:00 PM > To: arun > Cc: r-help > Su

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-28 Thread Verena Weinbir
Hey guys, thank you very much for your help. Since I am a R-newbie I am still checking out how your code works and how I could adapt it to my dataframe, which has 124 rows and 41 columns/variables. The first column would be "name", the last ones, 40 and 41, contain the cells I want to average fo

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-27 Thread arun
Hi, You can also try: dat <- read.table(text="Name C1 C2 C3   1  A  3  3  5   2  B  2  7  4   3  C  4  3  3   4  C  4  4  6   5  D  5  5  3",sep="",header=TRUE,stringsAsFactors=FALSE)  library(plyr)  ddply(dat,.(Name),numcolwise(mean,na.rm=TRUE)) A.K. On Tuesday, May 27, 2014 4:08 PM, Verena We

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-27 Thread Rui Barradas
Hello, Try the following. dat <- read.table(text = " Name C1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3 3 4 C 4 4 6 5 D 5 5 3 ", header = TRUE) str(dat) aggregate(dat[, -1], list(dat$Name), mean) Hope this helps, Rui Barradas Em 27-05-2014 21:06, Verena Weinbir escreve

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-27 Thread Greg Snow
Look at the aggregate function. As long as you have a column like Name that indicates which rows should be averaged together it will work (technically it will average the other rows as well, but since the average of 1 number is that number you will not see a difference). On Tue, May 27, 2014 at 2

[R] Dataframe: Average cells of two rows and replace them with one row

2014-05-27 Thread Verena Weinbir
Hello, I have a big dataframe, and want to average two specific cells of two specific rows and then replace those two rows with one row which contains the averaged cells. Example (row 3 and 4: Cells2 and Cells3 averaged and replaced) NameC1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3

Re: [R] dataframe

2014-04-29 Thread arun
Hi, It is better to show example data using ?dput(). dat <- structure(list(row.names = 1:4, XYZ = c("sample", "sample2", "sample3", "sample4"), `000_001` = c("sample", "Au5", "C", "C" ), `000_002` = c("sample", "Au32", "C", "Au4"), `000_003` = c("sample", "Au5", "A", "AC")), .Names = c("row.nam

[R] dataframe

2014-04-29 Thread pascalbe...@libero.it
Hello, thank you for accepting me into the list. I have the following dataframe: row.names X Y Z 000_001 000_002 000_003 1sample samplesample sample 2sample2 Au5 Au32 Au5

Re: [R] dataframe calculations based on certain values of a column

2014-03-27 Thread johannesradin...@gmail.com
Thanks, your solution using ave() works perfectly. /johannes -Ursprüngliche Nachricht- Von: Bert Gunter An: Johannes Radinger Cc: R help Gesendet: Mittwoch, 26. März 2014 16:45:43 GMT+00:00 Betreff: Re: [R] dataframe calculations based on certain values of a column I believe this

Re: [R] dataframe calculations based on certain values of a column

2014-03-26 Thread Noah Marconi
dplyr's group_by and mutate can create those columns for you: var1 <- c("a","b","c","a","b","c","a","b","c") var2 <- c("X","X","X","Y","Y","Y","Z","Z","Z") var3 <- c(1,2,2,5,2,6,7,4,4) df <- data.frame(var1,var2,var3) dt <- tbl_df(df) dt %.% group_by(var2) %.% mutate( div = var3[var1 =

Re: [R] dataframe calculations based on certain values of a column

2014-03-26 Thread Berend Hasselman
On 26-03-2014, at 17:09, Johannes Radinger wrote: > Hi, > > I have data in a dataframe in following structure > var1 <- c("a","b","c","a","b","c","a","b","c") > var2 <- c("X","X","X","Y","Y","Y","Z","Z","Z") > var3 <- c(1,2,2,5,2,6,7,4,4) > df <- data.frame(var1,var2,var3) > > Now I'd like to

Re: [R] dataframe calculations based on certain values of a column

2014-03-26 Thread Bert Gunter
I believe this will generalize. But check carefully! Using your example (Excellent!), use ave(): with(df,ave(seq_along(var1),var2,FUN=function(i) var3[i]/var3[i][var1[i]=="c"])) [1] 0.500 1.000 1.000 0.833 0.333 1.000 1.750 [8] 1.000 1.000 This is kind of a l

[R] dataframe calculations based on certain values of a column

2014-03-26 Thread Johannes Radinger
Hi, I have data in a dataframe in following structure var1 <- c("a","b","c","a","b","c","a","b","c") var2 <- c("X","X","X","Y","Y","Y","Z","Z","Z") var3 <- c(1,2,2,5,2,6,7,4,4) df <- data.frame(var1,var2,var3) Now I'd like to calculate relative values of var3. This values should be relative to th

Re: [R] R dataframe question

2014-01-25 Thread arun
Hi, dat1 <- read.table(text="X1 1,1 1,2 1,3 2,1 2,2 2,3 3,1 3,2 3,3",sep="",header=TRUE)  dat2 <- setNames(as.data.frame(matrix(dat1[,1],3,3)),paste0("X",1:3)) str(dat2) #'data.frame':    3 obs. of  3 variables: # $ X1: Factor w/ 3 levels "1,1","1,2","1,3": 1 2 3 # $ X2: Factor w/ 3 levels "2,1",

Re: [R] R dataframe question

2014-01-25 Thread arun
Hi, The question is not clear. set.seed(45)  spe <- data.frame(Col1=sample(c(1:10,letters[1:2]),400,replace=TRUE))  mat1 <- matrix(spe[,1],nrow=20,ncol=20) #If you want to replace the non-numeric values with NAs,  mat2 <- matrix(as.numeric(as.character(spe[,1])),nrow=20,ncol=20) A.K. Hell

Re: [R] dataframe manipulation

2013-12-13 Thread arun
Hi, Try:  d[match(unique(d$fac),d$fac),] A.K. On Friday, December 13, 2013 4:17 PM, Gang Chen wrote: Suppose I have a dataframe defined as     L3 <- LETTERS[1:3]     (d <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace = TRUE)))   x  y fac 1  1  1  C 2  1  2  A 3  1  3 

Re: [R] dataframe manipulation

2013-12-13 Thread William Dunlap
-project.org] On > Behalf > Of Gang Chen > Sent: Friday, December 13, 2013 1:35 PM > To: arun > Cc: R help > Subject: Re: [R] dataframe manipulation > > Perfect! Thanks a lot, A.K! > > > On Fri, Dec 13, 2013 at 4:21 PM, arun wrote: > > > > >

Re: [R] dataframe manipulation

2013-12-13 Thread Gang Chen
Another neat solution! Thanks a lot, Sarah! On Fri, Dec 13, 2013 at 4:35 PM, Sarah Goslee wrote: > What about: > > lapply(levels(d$fac), function(x)head(d[d$fac == x,], 1)) > > > Thanks for the reproducible example. If you put set.seed(123) before > the call to sample, then everyone who tries it

Re: [R] dataframe manipulation

2013-12-13 Thread Sarah Goslee
What about: lapply(levels(d$fac), function(x)head(d[d$fac == x,], 1)) Thanks for the reproducible example. If you put set.seed(123) before the call to sample, then everyone who tries it will get the same data frame d. Sarah On Fri, Dec 13, 2013 at 4:15 PM, Gang Chen wrote: > Suppose I have a

Re: [R] dataframe manipulation

2013-12-13 Thread Gang Chen
Perfect! Thanks a lot, A.K! On Fri, Dec 13, 2013 at 4:21 PM, arun wrote: > > > Hi, > Try: > d[match(unique(d$fac),d$fac),] > A.K. > > > On Friday, December 13, 2013 4:17 PM, Gang Chen > wrote: > Suppose I have a dataframe defined as > > L3 <- LETTERS[1:3] > (d <- data.frame(cbind(x

[R] dataframe manipulation

2013-12-13 Thread Gang Chen
Suppose I have a dataframe defined as L3 <- LETTERS[1:3] (d <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace = TRUE))) x y fac 1 1 1 C 2 1 2 A 3 1 3 B 4 1 4 C 5 1 5 B 6 1 6 B 7 1 7 A 8 1 8 A 9 1 9 B 10 1 10 A I want to extract

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
t;",x[-length(x)])); Nexttripstore<- ave(x2$Store,x2$PANID,FUN=function(x) c(x[-1],"")) } ) What am i doing wrong? - Original Message - From: arun To: R help Cc: Sent: Monday, September 2, 2013 11:29 PM Subject: Re: R dataframe and looping help HI Satish, colnam

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
;- lapply(seq_len(ncol(dat2)),function(i) { x1<-cbind(Output[,c(1:3)],dat2[,i]); colnames(Output)[4]<- colnames(dat2)[i]; x2<-x1[x1[,4]!=0,]; previoustripstore<-ave(x2$store,x2$CUSTID,FUN=function(x) c(NA,x[-length(x)])); Nexttripstore<- ave(x2$store,x2$CUSTID,FUN=function(x) c

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
HI, You may try this: dat1<- read.table(text=" CustID TripDate Store Bread Butter Milk Eggs 1 2-Jan-12 a 2 0 2 1 1 6-Jan-12 c 0 3 3 0 1 9-Jan-12 a 3 3 0 0 1 31-Mar-13 a 3 0 0 0 2 31-Aug-12 a 0 3 3 0 2 24-Sep-12 a 3 3 0 0 2 25-Sep-12 b 3 0 0 0 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat2<- d

Re: [R] Dataframe and conditions

2013-05-14 Thread arun
#this should also work  within(X,a<- ifelse(b,c,a)) #  a b c #1 2  TRUE 2 #2 2  TRUE 2 #3 1 FALSE 2 #4 1 FALSE 2 #5 1 FALSE 2 #6 2  TRUE 2 A.K. - Original Message - From: Pascal Oettli To: fgrelier Cc: r-help@r-project.org Sent: Tuesday, May 14, 2013 4:47 AM Subject: Re:

Re: [R] Dataframe and conditions

2013-05-14 Thread Frédéric Grelier
ine- De : arun [mailto:smartpink...@yahoo.com] Envoyé : mardi 14 mai 2013 15:19 À : Pascal Oettli Cc : R help; fgrelier Objet : Re: [R] Dataframe and conditions #this should also work  within(X,a<- ifelse(b,c,a)) #  a b c #1 2  TRUE 2 #2 2  TRUE 2 #3 1 FALSE 2 #4 1 FALSE 2 #5 1 FALSE

Re: [R] Dataframe and conditions

2013-05-14 Thread Pascal Oettli
Hello, One approach is using "ifelse": > X <- data.frame(a=c(1,1,1,1,1,1), b=c(TRUE,TRUE,FALSE,FALSE,FALSE,TRUE), c=c(2,2,2,2,2,2)) > X a b c 1 1 TRUE 2 2 1 TRUE 2 3 1 FALSE 2 4 1 FALSE 2 5 1 FALSE 2 6 1 TRUE 2 > > X <- within(X, a <- ifelse(b==TRUE, c, a)) > X a b c 1 2 TRUE 2

Re: [R] Dataframe and conditions

2013-05-14 Thread Rui Barradas
Hello, Try the following. X$a[X$b] <- X$c[X$b] Hope this helps, Rui Barradas Em 14-05-2013 09:06, fgrelier escreveu: I have in a dataframe X : 3 Variables X$a , X$b, X$c I would like to replace in X the values of X$a by the values of X$c but only when X$b=="TRUE" I have tried to put in

[R] Dataframe and conditions

2013-05-14 Thread fgrelier
I have in a dataframe X : 3 Variables X$a , X$b, X$c I would like to replace in X the values of X$a by the values of X$c but only when X$b=="TRUE" I have tried to put in place a loop but as I have a lot of rows it is very very long to run. Thanks for your help -- View this message in cont

Re: [R] Dataframe manipulation

2013-03-30 Thread englishfellow
Fantastic, thanks alot for that! Take care. Adam. Date: Sat, 30 Mar 2013 01:14:49 -0700 From: ml-node+s789695n466289...@n4.nabble.com To: english.fel...@hotmail.com Subject: Re: Dataframe manipulation Hi Adam, I hope this is what you wanted: dat1<- read.csv("example.csv",sep="\t",s

Re: [R] Dataframe manipulation

2013-03-30 Thread arun
Hi Adam, I hope this is what you wanted: dat1<- read.csv("example.csv",sep="\t",stringsAsFactors=FALSE)  str(dat1) #'data.frame':    102 obs. of  5 variables: # $ species  : chr  "B. barbastrellus" "E. nilssonii" "H. savii" "M. alcathoe" ... # $ period   : chr  "dusk" "dusk" "dusk" "dusk" ... # $

Re: [R] Convert json data to an r dataframe

2012-12-28 Thread sp.duccio
omJSON(url) > >> > >> str(dat) # List with 3 components > >> > >> str(dat[[1]][[1]]) > >> dat[[1]][[1]] > >> > >> str(dat[[1]][[2]]) > >> unlist(dat[[1]][[2]]) > >> > >> str(dat[[1]][[3]]) > >> dat[[1]][[3

Re: [R] Convert json data to an r dataframe

2012-12-28 Thread Jeff Newmiller
amp;te=";<http://apistat.istat.it/?q=getdatajson&dataset=DCIS_POPSTRBIL&dim=1,0,0,0&lang=1&tr=&te=> >> dat <- fromJSON(url) >> >> str(dat) # List with 3 components >> >> str(dat[[1]][[1]]) >> dat[[1]][[1]] >> >> s

Re: [R] Convert json data to an r dataframe

2012-12-28 Thread sp.duccio
][[1]]) > dat[[1]][[1]] > > str(dat[[1]][[2]]) > unlist(dat[[1]][[2]]) > > str(dat[[1]][[3]]) > dat[[1]][[3]] > > > Hope this helps, > > Rui Barradas > Em 27-12-2012 11:55, sp.duccio escreveu: > > Hello to everybody, > > I need to convert a json datas

Re: [R] Convert json data to an r dataframe

2012-12-27 Thread Rui Barradas
escreveu: > Hello to everybody, > > I need to convert a json dataset in an R dataframe. > I suppose that I'd need to use rjson or rjsonio package. > The json dataset is: > http://apistat.istat.it/?q=getdatajson&dataset=DCIS_POPSTRBIL&dim=1,0,0,0&lang=1&tr=&am

[R] Convert json data to an r dataframe

2012-12-27 Thread sp.duccio
Hello to everybody, I need to convert a json dataset in an R dataframe. I suppose that I'd need to use rjson or rjsonio package. The json dataset is: http://apistat.istat.it/?q=getdatajson&dataset=DCIS_POPSTRBIL&dim=1,0,0,0&lang=1&tr=&te= It would be nice if someon

Re: [R] Dataframe,Matrix,Table

2012-11-08 Thread John Kane
nal Message- > From: kokila.krish...@quantilez.com > Sent: Thu, 8 Nov 2012 02:18:22 -0800 (PST) > To: r-help@r-project.org > Subject: [R] Dataframe,Matrix,Table > > Hi for all... > > I am having one Dataset. Mode of the dataset is dataframe. I need to add &g

[R] Dataframe,Matrix,Table

2012-11-08 Thread kokila
Hi for all... I am having one Dataset. Mode of the dataset is dataframe. I need to add headerline,row and column line. How to do this...Help me to do this Thanks Kokila -- View this message in context: http://r.789695.n4.nabble.com/Dataframe-Matrix-Table-tp4648843.html Sent f

Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread Ajay Askoolum
Thank you Jorge & Michael. I was being stupid - its the only explanation! The line I had been executing was mtcars[rownames=="Valiant"] # missing rownames argument but the line I quoted in my post was mtcars[rownames(mtcars) != "Valiant",]  # How could I write the correct line in the mailin

Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread R. Michael Weylandt
Hi Ajay, Like Jorge, I can't seem to reproduce the behavior you are worried about. mtcars[rownames(mtcars) != "Valiant",] returns a 31x11 data.frame as expected. When you say it "fails," what error message / result are you seeing? Michael On Fri, Feb 17, 2012 at 3:27 AM, Jorge I Velez wrote

Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread Jorge I Velez
Hi Ajay, In the first case, you need "==" instead of "=" : R> mtcars[ rownames(mtcars) == "Valiant", ] mpg cyl disp hp drat wt qsec vs am gear carb Valiant 18.1 6 225 105 2.76 3.46 20.22 1 031 For the second case, R> mtcars[rownames(mtcars) != "Valiant",] will do it. See als

[R] Dataframe subset - why doesn't this work?

2012-02-17 Thread Ajay Askoolum
data(mtcars) mtcars[rownames(mtcars)!="Valiant",] # fails mtcars[list(rownames(mtcars))!="Valiant",] # runs but I am not getting the expected result With the latter statement, I expected all rows except the one where the name is "Valiant". I must have got something simple wrong; what is it?

Re: [R] dataframe: how to select an element from a row

2012-01-20 Thread ikuzar
This works but I do not know if there is a better way tmp = df[df$myvalue<2000,] ind = match(tmp$myvalue, df$myvalue) res = df$DateTime[ind] solution = list(ind[1], res[1]) -- View this message in context: http://r.789695.n4.nabble.com/dataframe-how-to-select-an-element-from-a-row-tp4311881p43

Re: [R] dataframe: how to select an element from a row

2012-01-20 Thread ikuzar
Thank you Jorge and Florent for your responses. Now, I 'd like to get the date *(and its index) *where myvalue < 2000 for the first time. I expect for a result like (index, date) = (3, 2012-01-07 ) This way does not work: ind = match(df$myvalue <2000, df$myvalue) res = df$DateTime[ind] -- View

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Jorge I Velez
Thank you Florent, it really helps. Regards, Jorge.- On Thu, Jan 19, 2012 at 7:28 PM, Florent D. <> wrote: > Another possibility: > > df$Date[match(1800, df$myvalue)] > > match() stops at the first value encountered so it may be a bit faster > than a full subset(), depending on your table size.

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Florent D.
Another possibility: df$Date[match(1800, df$myvalue)] match() stops at the first value encountered so it may be a bit faster than a full subset(), depending on your table size. Another difference: this approach would return NA if there was no match, subset(...)[1, ] would trigger an error. Depend

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Jorge I Velez
Hi ikuzar, Try subset(df, myvalue == 1800, select = Date)[1, ] See ?subset for more information. HTH, Jorge.- On Thu, Jan 19, 2012 at 6:42 PM, ikuzar <> wrote: > Hi, > I 'd like to select the Date where myvalue =1800 appears the* first time*. > > For instance: > df =data.frame(date, myvalue,

[R] dataframe: how to select an element from a row

2012-01-19 Thread ikuzar
Hi, I 'd like to select the Date where myvalue =1800 appears the* first time*. For instance: df =data.frame(date, myvalue, ...) ... Datemyvalue 2012-01-052500 2012-01-06 2450 *2012-01-07 1800* 2012-01-08

Re: [R] dataframe indexing by number of cases per group

2011-11-24 Thread Johannes Radinger
t; Datum: Thu, 24 Nov 2011 09:12:57 -0500 > Von: Gabor Grothendieck > An: Johannes Radinger > CC: r-help@r-project.org > Betreff: Re: [R] dataframe indexing by number of cases per group > On Thu, Nov 24, 2011 at 7:02 AM, Johannes Radinger > wrote: > > Hello, > > &g

Re: [R] dataframe indexing by number of cases per group

2011-11-24 Thread Gabor Grothendieck
On Thu, Nov 24, 2011 at 7:02 AM, Johannes Radinger wrote: > Hello, > > assume we have following dataframe: > > group <-c(rep("A",5),rep("B",6),rep("C",4)) > x <- c(runif(5,1,5),runif(6,1,10),runif(4,2,15)) > df <- data.frame(group,x) > > Now I want to select all cases (rows) for those groups > whi

Re: [R] dataframe indexing by number of cases per group

2011-11-24 Thread Dennis Murphy
A very similar question was asked a couple of days ago - see the thread titled "Removing rows in dataframe w'o duplicated values" - in particular, the responses by Dimitris Rizopoulos and David Winsemius. The adaptation to this problem is df[ave(as.numeric(df$group), as.numeric(df$group), FUN = le

[R] dataframe indexing by number of cases per group

2011-11-24 Thread Johannes Radinger
Hello, assume we have following dataframe: group <-c(rep("A",5),rep("B",6),rep("C",4)) x <- c(runif(5,1,5),runif(6,1,10),runif(4,2,15)) df <- data.frame(group,x) Now I want to select all cases (rows) for those groups which have more or equal 5 cases (so I want to select all cases of group A and

Re: [R] dataframe - column value calculation in R

2011-05-26 Thread Timothy Bates
On 26 May 2011, at 08:02, Vijayan Padmanabhan wrote: > I have a requirement for which I am seeking help. Best to just ask, compactly. This is a very straightforward question: best to read on how to use R: You are just set 1 column of a dataframe to a value based on the others, applying this to

[R] dataframe - column value calculation in R

2011-05-26 Thread Vijayan Padmanabhan
Dear RGroup I have a requirement for which I am seeking help. I am looking at automating the last column calculation through R when having the data of the other columns as a dataframe, In excel I can do using the formula function as given below, however, hereagain for the number of observations

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Daniele Amberti
sDaply2(X, X$ID) # list is not a timeSeries object str(cbind(t(res))) res <- as.timeSeries(cbind(t(res))) -Original Message- From: h.wick...@gmail.com [mailto:h.wick...@gmail.com] On Behalf Of Hadley Wickham Sent: 14 March 2011 15:07 To: Daniele Amberti Cc: r-help@r-project.org Subjec

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Hadley Wickham
>  res <- daply(X, "ID", buildTimeSeriesFromDataFrame2, .parallel = FALSE) >  return(res) > } > # tsDaply2 .parallel = FALSE work but list discart timeSeries class > > # bind after ts creation > res <- tsDaply2(X, X$ID) > # list is not a timeSeries object &g

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Daniele Amberti
ot;, buildTimeSeriesFromDataFrame2, .parallel = FALSE) return(res) } # tsDaply2 .parallel = FALSE work but list discart timeSeries class # bind after ts creation res <- tsDaply2(X, X$ID) # list is not a timeSeries object str(cbind(t(res))) res <- as.timeSeries(cbind(t(res))) stopW

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Hadley Wickham
Well, I'd start by removing all explicit use of environments, which makes you code very hard to follow. Hadley On Monday, March 14, 2011, Daniele Amberti wrote: > I found that plyr:::daply is more efficient than base:::by (am I doing > something wrong?), below updated code for comparison (I als

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Daniele Amberti
I found that plyr:::daply is more efficient than base:::by (am I doing something wrong?), below updated code for comparison (I also fixed a couple things). Function daply from plyr package has also a .parallel argument and I wonder if creating timeseries objects in parallel and then combining th

[R] dataframe to a timeseries object

2011-03-11 Thread Daniele Amberti
I’m wondering which is the most efficient (time, than memory usage) way to obtain a multivariate time series object from a data frame (the easiest data structure to get data from a database trough RODBC). I have a starting point using timeSeries or xts library (these libraries can handle time zo

  1   2   3   >