Entering edit mode
4.6 years ago
blacktomato27
▴
70
Hi to all
i am reading my csv files into R with read.csv function and i did it and tried to see row names of the imported file and i am getting row names like numbers like this
"1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13",
but
my row names are like this RED, RED1, RED2,,,,,, TILL RED12
. I used this code to read
file1 <- read.csv("example.csv", header = TRUE, sep =",", stringsAsFactors=T).
can any one help to solve this? i used to read csv files with above code i never faced problem like this suprisingly this time only. any help in this regard would be highly appreciated.
Thanks in advance
I am a bit confused on what the dataframe actually looks like, can you do
head(df)
and paste the result here (df is name of your dataframe)? If you mean that there is an additional column which is displaying those rownames (1,2,3..) then have you tried getting rid of it by sayingrow.names(df) = NULL
hi manaswwm this is how my data in file INDIVIDUAL MALE FEMALE RED A/A A/A RED1 T/T T/T RED2 C/C C/C RED3 G/G G/G RED4 A/A A/A RED5 T/T T/T and if i tried head(df) i am getting like this INDIVIDUAL MALE FEMALE 1 RED A/A A/A 2 RED1 T/T T/T 3 RED2 C/C C/C 4 RED3 G/G G/G 5 RED4 A/A A/A 6 RED5 T/T T/T in head(df) i am getting exactly what i want, but when i tried row.names(df) i am getting only numbers in place of row names.
What do you get when you add the parameter row.names=1 ?
dear sam Thanks for your reply, its is reading row names when i use row.names=1 i am getting like this MALE FEMALE RED A/A A/A RED1 T/T T/T RED2 C/C C/C RED3 G/G G/G RED4 A/A A/A RED5 T/T T/T but when i tried head(df) it is not showing my first column name and i am unable to that column based on its name
Can you please try to format your posts a bit better -- it is almost impossible to discern the structure of your file from your previous posts. You can, for example, use the button with 101's to get appropriate code chunk formatting.
That being said, if
head(df)
gives you what you want after usingfile1 <- read.csv("example.csv", header = TRUE, sep =",", stringsAsFactors=T)
you may simply need to add the row.names manually after reading the file in, e.g.:Hi friederike Good Morning Sorry for my not fine post here, i do not know how to post perfectly and thanks for your suggestion. Actually i want to one extra column (POP) in file1 based on INDIVIDUAL COLUMN from file2. please check this link for my example files and code code - https://www.dropbox.com/s/3l8m6ejkaytrer0/groupwise%20dendro%20grams%20code%20-%20Copy.txt?dl=0 file1 - https://www.dropbox.com/s/z5fxwm8mzxpdkrx/example1.csv?dl=0 file2 - https://www.dropbox.com/s/r0g1d9k25e8yppz/example2.csv?dl=0 the same worked for me in my previous work and all of a sudden it is throwing row numbers with out column heading and difficult to merge. I do not know what is reason for this sudden happening in R. Thanking you very much for your help
I tried running your code. Reading the csv and merging works. If you want the result to have row names, then you should use.
The second line leaves all column names that are NOT the individual column name (not in the most efficient way... )
check
?read.csv
to see the info about therow.names
option: