Re: [R-SIG-Mac] Unable to change some members of a vector
Just incidentally, \xCA in MacRoman encoding is an NBSP – non-breaking space, which is the only one that looks sane. In Unicode, it’s Latin capital letter E with circumflex, as it is in ISO 8859-1. Peter — p...@ehealth.id.au Moved with pity, he stretched out his hand and touched him and said to him, “I will; be clean.” > On 14 Feb 2021, at 2:34 pm, Ken Beath wrote: … > There is an option in the read.table command of stringsAsFactors. You can set > it to FALSE to obtain character strings. You can also convert the factor to > character using as.character(). > … > Ken > >> On 14 Feb 2021, at 9:54 am, Parkhurst, David F. wrote: >> >> I have a problem I don’t know how to deal with. I’ve used read.table to >> create the data frame called msPdf. It contains three vectors: month, >> site, conc. Some of the site values look like this: MLH\xca. [[alternative HTML version deleted]] ___ R-SIG-Mac mailing list R-SIG-Mac@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac
Re: [R-SIG-Mac] Unable to change some members of a vector
This question is not related to Macs, but here is the answer anyway. First up, anyone who uses R should understand what a factor is. Find an introductory text on R and read the section on factors. Even better, read the whole book. It seems that it has been decided that R will not automatically add a factor level, which is probably a good idea. There is an option in the read.table command of stringsAsFactors. You can set it to FALSE to obtain character strings. You can also convert the factor to character using as.character(). If Excel decides to put strange characters into your data file then that is Excel’s problem. I suggest looking at the file with a text editor. The free version of BBEdit will work fine. You can read Excel files directly using teh readxl package. Ken > On 14 Feb 2021, at 9:54 am, Parkhurst, David F. wrote: > > I have a problem I don’t know how to deal with. I’ve used read.table to > create the data frame called msPdf. It contains three vectors: month, site, > conc. Some of the site values look like this: MLH\xca. I was able to > change that with this command: msPdf$site[13]="MLH”. That seems to have been > allowed because some of the other sites are simply MLH. But the system won’t > let me make the same kind of change in another case: > msPdf$site[29]="MUH”. When I ask for that, I get > Warning message: > In `[<-.factor`(`*tmp*`, 29, value = c(5L, 2L, 1L, 11L, 5L, 12L, : > invalid factor level, NA generated >> #13 May MLH\xca 0.007 > Then if I enter msPdf$site[29], I get this response: > [1] > Levels: CrCr LMO MCE MCH MFSC MLE MLH MLH\xca MUE MUH\xca NFSC SFSC > > In other words, although other sites that were just plain MLH, there were not > other sites that were just plain MUH. > How can I fix this problem? I have no idea why excel added those \xca bits > to a few of the site values. > > ___ > R-SIG-Mac mailing list > R-SIG-Mac@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-mac ___ R-SIG-Mac mailing list R-SIG-Mac@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac
[R-SIG-Mac] Unable to change some members of a vector
I have a problem I don’t know how to deal with. I’ve used read.table to create the data frame called msPdf. It contains three vectors: month, site, conc. Some of the site values look like this: MLH\xca. I was able to change that with this command: msPdf$site[13]="MLH”. That seems to have been allowed because some of the other sites are simply MLH. But the system won’t let me make the same kind of change in another case: msPdf$site[29]="MUH”. When I ask for that, I get Warning message: In `[<-.factor`(`*tmp*`, 29, value = c(5L, 2L, 1L, 11L, 5L, 12L, : invalid factor level, NA generated > #13 May MLH\xca 0.007 Then if I enter msPdf$site[29], I get this response: [1] Levels: CrCr LMO MCE MCH MFSC MLE MLH MLH\xca MUE MUH\xca NFSC SFSC In other words, although other sites that were just plain MLH, there were not other sites that were just plain MUH. How can I fix this problem? I have no idea why excel added those \xca bits to a few of the site values. ___ R-SIG-Mac mailing list R-SIG-Mac@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac