Re: [R] assignment operator saving factor level as number

2010-11-05 Thread Jeffrey Spies
Glad you figured it out, but just be aware that if you set one value of the column to be a character, it will make the whole vector characters. This could cause issues for analysis if you need numerics or factors. If the column is supposed to be a factor to begin with, set it to be so; if you hav

Re: [R] assignment operator saving factor level as number

2010-11-05 Thread Wade Wall
Hi all, Thanks for the help. Jeffrey was right; my initial dataframe did not have the columns defined for factors. I solved it using Jorge's example of using as.character. Sorry for not being more clear before. Wade On Fri, Nov 5, 2010 at 4:12 PM, Jeffrey Spies wrote: > Perhaps this will he

Re: [R] assignment operator saving factor level as number

2010-11-05 Thread Jorge Ivan Velez
Hi Wade, Try (untested): df2[j,1] <- as.character(f2$Site)[i] If that does not work, which is very likely, could you please provide commented, minimal, self-contained, reproducible code? HTH, Jorge On Fri, Nov 5, 2010 at 3:54 PM, Wade Wall <> wrote: > Hi all, > > I have a dataframe (df1) tha

Re: [R] assignment operator saving factor level as number

2010-11-05 Thread Jeffrey Spies
Perhaps this will help: > test1 <- test2 <- data.frame(col1=factor(c(1:3), labels=c("a", "b", "c"))) > test3 <- data.frame(col1 = 1:3) Now: > test2[2,1] <- test1$col1[1] > test2$col1 [1] a a c Levels: a b c vs > test3[2,1] <- test1$col1[1] > test3$col1 [1] 1 1 3 Because test3's first column,

Re: [R] assignment operator saving factor level as number

2010-11-05 Thread jim holtman
Your example looks like you are assigning back to the first column of df2 (Num). Is this what you are really doing in your code? You need to follow the posting guide: PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, repr

Re: [R] assignment operator saving factor level as number

2010-11-05 Thread Erik Iverson
Could you give a small reproducible example please? It is not clear to me what your looping structure is doing, or what your goal here is. There may be a much simpler method than introducing subscripts. --Erik Wade Wall wrote: Hi all, I have a dataframe (df1) that I am trying to select values

[R] assignment operator saving factor level as number

2010-11-05 Thread Wade Wall
Hi all, I have a dataframe (df1) that I am trying to select values from to a second dataframe that at the current time is only for the selected items from df1 (df2). The values that I am trying to save from df1 are factors with alphanumeric names df1 looks like this: 'data.frame': 3014 obs. o