similar to: Factor vs character in a data.frame vs vector

Displaying 20 results from an estimated 30000 matches similar to: "Factor vs character in a data.frame vs vector"

2017 Jul 07
0
Factor vs character in a data.frame vs vector
> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help at r-project.org> wrote: > > This is not serious problem but I just wonder if someone can explain what is happening. > The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask.
2017 Jul 08
2
Factor vs character in a data.frame vs vector
Thanks Marc. It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <marc_schwartz at me.com> wrote: > On Jul 7, 2017, at 6:03
2017 Jul 08
0
Factor vs character in a data.frame vs vector
> On Jul 7, 2017, at 7:03 PM, John Kane <jrkrideau at yahoo.ca> wrote: > > Thanks Marc. > It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame. I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. Welcome John. Going back to
2017 Jul 15
2
One Dimensional Monte Carlo Simulation
Further to my email below, I have just realised that I forgot to include the specification of L and R. Hence, the code needs to include the following additional lines at the start;- L<-7.5e6 R<-2.5e6 Apologies for any confusion caused! Best regards, Tony > On 12 Jul 2017, at 10:03 AM, HUL-Anthony Egerton <aegerton at huntingtonunderwriting.com> wrote: > > I am trying
2017 Aug 01
0
One Dimensional Monte Carlo Simulation
Tony, I?m not sure what exactly you?re trying to do, but you're not really taking advantage of vectorization in your R code. I've tried to clean it up a little. The clamped lognormal is almost always 0 or L? That seems a little odd. You seem to be using the inverse cdf method of drawing samples. That's not necessary in R for standard probability distributions. You may want to do a
2013 Aug 26
1
Loop for converting character columns to Numeric
Hi, Suppose you created a dataframe like this: set.seed(28) ?dat1<-as.data.frame(simplify2array(list(letters[1:5],sample(1:20,5,replace=TRUE),6:10)),stringsAsFactors=FALSE) ?str(dat1) #'data.frame':??? 5 obs. of? 3 variables: # $ V1: chr? "a" "b" "c" "d" ... # $ V2: chr? "1" "2" "10" "18" ... # $ V3: chr?
2013 Feb 17
1
addition in the initial question
Dear Elisa, Try this: vec1<-c(33,18,13,47,30,10,6,21,39,25,40,29,14,16,44,1,41,4,15,20,46,32,38,5,31,12,48,27,36,24,34,2,35,11,42,9,8,7,26,22,43,17,19,28,23,3,49,37,50,45) vec2<-vec1[1:26] names(vec2)<-LETTERS[1:26] label1<-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) x),lapply(seq(5,50,5),function(x) x),SIMPLIFY=FALSE),function(i)
2013 Sep 02
1
R dataframe and looping help
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<- dat1[,-c(1:3)] res<- lapply(seq_len(ncol(dat2)),function(i)
2013 Jan 04
2
Can you help me please
HI Fares, You could try this: dat1<- read.table(text=" date????? donation 3jan2003?? 20235 4jan2003?? 25655 5jan2003?? 225860 6jan2003?? 289658 7jan2003?? 243889 8jan2003?? 244338 9jan2003?? 243889 ",sep="",header=TRUE,stringsAsFactors=FALSE) The post is not very specific as to what you need.? I hope this works for you. library(xts)
2013 May 22
1
Something Very Easy
HI, I am not sure about what you expect as output. dat1<- read.table(text=" Offense Play Y??????? A N??????? B Y??????? A Y??????? C N??????? B N??????? C ",sep="",header=TRUE,stringsAsFactors=FALSE) ?with(dat1,tapply(Play,list(Offense),table)) #$N # #B C #2 1 # #$Y # #A C #2 1 #or with(dat1,tapply(factor(Play),list(Offense),table)) #$N # #A B C #0 2 1 # #$Y # #A B
2013 Mar 29
1
Dataframe manipulation
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"
2013 Jan 23
4
extracting characters from a string
Dear All, I have a data frame of vectors of publication names such as 'pub': pub1 <- c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 <- c('Benigni D') pub3 <- c('Arstra SD, Van den Hoops DD, lamarque D') pub <- rbind(pub1, pub2, pub3) I would like to construct a dataframe with only author's last name and each last name in columns and the
2013 Sep 02
1
Convert chr pieces to numbers that have specific values defined by 2 vectors
Dear all, I think this is an easy task, but I don't know how to do it. Specifically, I have 69 columns with 300.000 rows. In each cell there is a code like "2E3", "4RR", etc. I now have a list that replaces this with values, e.g., old new 2E3 5 4RR 3 etc. The list ist about 1600 rows long, so also to extensive for normal solutions Do you how to do that? It would
2013 Apr 12
2
split date and time
Hi R experts, For example I have a dataset looks like this: Number TimeStamp Value 1 1/1/2013 0:00 1 2 1/1/2013 0:01 2 3 1/1/2013 0:03 3 How can I split the "TimeStamp" Column into two and return a new table like this: Number Date Time Value 1 1/1/2013 0:00 1 2 1/1/2013 0:01 2 3 1/1/2013 0:03 3 Thank! [[alternative HTML version
2013 Mar 19
4
Copying rows in data frames
Hi, I'm trying to copy the first row of one data frame to another. This is the statement I am using : df2[1,]<-df1[1,]; I have printed them out separately: df1[1,] = A C D E F But after copying: df2[1,] = 96 29 88 122 68 Why isn't it copying? They are both data frames, and "as.character" isn't working either. Thanks for your input :) [[alternative HTML version
2018 May 11
0
add one variable to a data frame
Sarah's solutions are good, and here's another, even more basic: tmp1 <- unique(dat1$B) tmp2 <- seq_along(tmp1) dat1$C <- tmp2[ match( dat1$B, tmp1) ] > dat1 N B C 1 1 29_log 1 2 2 29_log 1 3 3 29_log 1 4 4 27_cat 2 5 5 27_cat 2 6 6 1_log 3 7 7 1_log 3 8 8 1_log 3 9 9 1_log 3 10 10 1_log 3 11 11 3_cat 4 12 12 3_cat 4 As a single line
2011 Oct 25
4
comparing two tables
Hi everybody, I would like to know whether it is possible to compare to tables for certain parameters. I have these two tables: gene table name chr start end str accession Length gen1 4 646752 646838 + MI0005806 86 gen12 2L 243035 243141 - MI0005821 106 gen3 2L 159838 159928 + MI0005813 90 gen7 2L
2018 May 11
3
add one variable to a data frame
Hi Sarah, Thank you so much!! I got your good ideas. Ding -----Original Message----- From: Sarah Goslee [mailto:sarah.goslee at gmail.com] Sent: Friday, May 11, 2018 11:40 AM To: Ding, Yuan Chun Cc: r-help mailing list Subject: Re: [R] add one variable to a data frame [Attention: This email came from an external source. Do not open attachments or click on links from unknown senders or
2013 Apr 23
1
Extract part of a numer
Hi, May be this helps: set.seed(25) dat1<- data.frame(ID=c("1001#01","1001#02","1001#03","1002#01","1002#02"),val=rnorm(5),stringsAsFactors=FALSE) ?dat1$ID<-as.numeric(gsub("#.*","",dat1$ID)) ?dat1 #??? ID??????? val #1 1001 -0.2118336 #2 1001 -1.0415911 #3 1001 -1.1533076 #4 1002? 0.3215315 #5 1002 -1.5001299 A.K.
2010 Aug 20
2
Determining the length of unique items in a vector
Dear all, let suppose I have following vector:   > dat1 <- c(rep("asd", 5), rep("xyz", 12), rep("erd", 17)) > dat1 <- dat1[sample(1:length(dat1), length(dat1), replace=F)] > dat1  [1] "erd" "xyz" "erd" "asd" "asd" "erd" "xyz" "asd" "erd" "erd"