Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6149665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:29:29+00:00 2026-05-23T19:29:29+00:00

Define: df <- data.frame(name=c(México,Michoacán),dat=c(1,2)) s.t. > df name dat 1 México 1 2 Michoacán

  • 0

Define:

df <- data.frame(name=c("México","Michoacán"),dat=c(1,2))

s.t.

> df
        name dat
1    México   1
2 Michoacán   2

When I print this table to a .tex file using xtable the accented characters get garbled, which is no surprise.

I would like to replace accents with proper Latex formatting e.g.:

> df
     name dat
1 M\'{e}xico   1
2 Michoac\'{a}n   2

Please note in real dataset there are many different names with different accented letters but all with same type of accent (i.e. foward-slash), so the only thing that needs to change in \'{.} is the letter in place of the dot.

In trying one reader’s suggestion i did the following:

> df <- data.frame(name=c("México","Michoacán"),dat=c(1,2))
> df
        name dat
1    México   1
2 Michoacán   2
> df$name <- sub("é", "\\\\'{e}", df$name,)
> df
         name dat
1 M\\'{e}xico   1
2  Michoacán   2
> capture.output(
+       print(xtable(df)),
+       file = "../paper/rTables.tex", append = FALSE)

When I opened the rTables.tex file in Notepad:

% latex table generated in R 2.13.1 by xtable 1.5-6 package
% Fri Jul 15 13:19:17 2011
\begin{table}[ht]
\begin{center}
\begin{tabular}{rlr}
  \hline
 & name & dat \\ 
  \hline
1 & M$\backslash$'\{e\}xico & 1.00 \\ 
  2 & Michoacán & 2.00 \\ 
   \hline
\end{tabular}
\end{center}
\end{table}

This is not what is needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:29:30+00:00Added an answer on May 23, 2026 at 7:29 pm

    I think the problem is that this case is asking a lot of xtable‘s attempts to convert strange characters to LaTeX. Try overriding sanitize.text.function as follows:

    print(xtable(df),sanitize.text.function=function(x){x})
    

    which on my system outputs this:

    % latex table generated in R 2.13.0 by xtable 1.5-6 package
    % Fri Jul 15 10:30:00 2011
    \begin{table}[ht]
    \begin{center}
    \begin{tabular}{rlr}
      \hline
     & name & dat \\ 
      \hline
    1 & M\'{e}xico & 1.00 \\ 
      2 & Michoacán & 2.00 \\ 
       \hline
    \end{tabular}
    \end{center}
    \end{table}
    

    It might be that other LaTeX markup may be broken by doing this, though, so be aware of that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given a string: msg=hello world How can I define this as a ctypes.c_void_p() data
I'm using R to loop through a data frame, perform a calculation and to
Define: df1 <-data.frame( id=c(rep(1,3),rep(2,3)), v1=as.character(c(a,b,b,rep(c,3))) ) s.t. > df1 id v1 1 1 a
Define: > dats <- list( df1 = data.frame(a=sample(1:3), b = as.factor(rep(325.049072M,3))), + df2 =
Define: df <- data.frame( line1 = rep(seq(1,5,by=1),2), line2 = rep(seq(2,6,by=1),2), index = rep(seq(1,5,by=1),2), factor=rep(c(a,b),each=5))
I have a data frame that looks like this: site date var dil 1
I'm trying to define a Data Driven Subscription for a report in SSRS 2005.
What is the best approach to define additional data for typedef enums in C?
The class corresponding to this crash is: #ifndef IMAGE_DATA_ #define IMAGE_DATA_ #include <stdexcept> template
What type of data I should define on my java model for PostgreSQL money

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.