I have a problem in R and hope someone can help me.
I have a dataframe of 400 rows an 2448 columns. I just wanted to create a new dataframe with a new order of the columns, so I wrote the following script:
Daten_ausgewaehlt_weniger_sort <- Daten_ausgewaehlt_weniger[,c("id", "p_sex", "p_age", "p_single", "p_mothertongue", "p_mothertongue_other",
"p_courseofstudies_yes_no", "p_courseofstudies", "p_occupation")]
(With the difference that in my real script I have all of my 2448 columns in the c-vector and not just these 9 as here displayed.)
When I try to run this, i get this error message:
Error in
[.data.frame
(Daten_ausgewaehlt_weniger, , c("id", "p_sex", : undefined columns selected
I searched for wrong spelled column-names with this function:
setdiff(names(Daten_ausgewaehlt_weniger), c("id", "p_sex", "p_age", "p_single", "p_mothertongue", "p_mothertongue_other",
"p_courseofstudies_yes_no", "p_courseofstudies", "p_occupation"))
First I found one wrong column name, but I corrected it and now the setdiff says "character(0)". So all column names should be defined right. But I still get the same error with "undefined columns selected".
I don't know what the mistake is. I think it is a really easy thing I want to do, but I don`t find a solution. I would be very happy if anyone could help me or has ideas what I could try.
Thanks in advance (and sorry for my english)!